typescript-virtual-container 1.3.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -1
- package/builds/self-standalone.js +481 -0
- package/builds/self-standalone.js.map +7 -0
- package/{standalone-wo-sftp.js → builds/standalone-wo-sftp.js} +137 -137
- package/{standalone-wo-sftp.js.map → builds/standalone-wo-sftp.js.map} +4 -4
- package/{standalone.js → builds/standalone.js} +176 -176
- package/{standalone.js.map → builds/standalone.js.map} +4 -4
- package/builds/web-full-api.min.js +13 -0
- package/builds/web-full-api.min.js.map +7 -0
- package/builds/web-iife.min.js +13 -0
- package/builds/web-iife.min.js.map +7 -0
- package/builds/web.min.js +13 -0
- package/builds/web.min.js.map +7 -0
- package/dist/SSHMimic/loginBanner.d.ts +7 -0
- package/dist/SSHMimic/loginBanner.d.ts.map +1 -0
- package/dist/SSHMimic/loginBanner.js +22 -0
- package/dist/VirtualShell/index.d.ts +21 -1
- package/dist/VirtualShell/index.d.ts.map +1 -1
- package/dist/VirtualShell/index.js +34 -2
- package/dist/VirtualShell/shell.d.ts.map +1 -1
- package/dist/VirtualShell/shell.js +2 -17
- package/dist/self-standalone.d.ts +2 -0
- package/dist/self-standalone.d.ts.map +1 -0
- package/dist/self-standalone.js +147 -0
- package/dist/web-api.d.ts +26 -0
- package/dist/web-api.d.ts.map +1 -0
- package/dist/web-api.js +46 -0
- package/dist/web-full.d.ts +4 -0
- package/dist/web-full.d.ts.map +1 -0
- package/dist/web-full.js +8 -0
- package/dist/web.d.ts +108 -0
- package/dist/web.d.ts.map +1 -0
- package/dist/web.js +773 -0
- package/examples/README.md +81 -3
- package/examples/app-iife.js +58 -0
- package/examples/app.js +28 -0
- package/examples/index-cf.html +27 -0
- package/examples/index.html +27 -0
- package/examples/server.js +55 -0
- package/examples/web-iife.min.js +13 -0
- package/examples/web.min.js +13 -0
- package/package.json +10 -3
- package/polyfills/node:child_process/index.js +2 -0
- package/polyfills/node:crypto/index.js +7 -0
- package/polyfills/node:events/index.js +9 -0
- package/polyfills/node:fs/index.js +8 -0
- package/polyfills/node:fs/promises.js +4 -0
- package/polyfills/node:os/index.js +9 -0
- package/polyfills/node:path/index.js +14 -0
- package/polyfills/node:vm/index.js +7 -0
- package/polyfills/node:zlib/index.js +3 -0
- package/src/SSHMimic/loginBanner.ts +36 -0
- package/src/VirtualShell/index.ts +60 -2
- package/src/VirtualShell/shell.ts +3 -31
- package/src/self-standalone.ts +183 -0
- package/src/web-api.ts +62 -0
- package/src/web-full.ts +11 -0
- package/src/web.ts +930 -0
- package/tests/web.test.ts +182 -0
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
"use strict";var Hh=Object.create;var _c=Object.defineProperty;var Qh=Object.getOwnPropertyDescriptor;var Wh=Object.getOwnPropertyNames;var qh=Object.getPrototypeOf,Kh=Object.prototype.hasOwnProperty;var at=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports);var Vh=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Wh(t))!Kh.call(n,s)&&s!==e&&_c(n,s,{get:()=>t[s],enumerable:!(r=Qh(t,s))||r.enumerable});return n};var Vt=(n,t,e)=>(e=n!=null?Hh(qh(n)):{},Vh(t||!n||!n.__esModule?_c(e,"default",{value:n,enumerable:!0}):e,n));var rs=at((Cx,ru)=>{ru.exports={newInvalidAsn1Error:function(n){var t=new Error;return t.name="InvalidAsn1Error",t.message=n||"",t}}});var is=at((vx,iu)=>{iu.exports={EOC:0,Boolean:1,Integer:2,BitString:3,OctetString:4,Null:5,OID:6,ObjectDescriptor:7,External:8,Real:9,Enumeration:10,PDV:11,Utf8String:12,RelativeOID:13,Sequence:16,Set:17,NumericString:18,PrintableString:19,T61String:20,VideotexString:21,IA5String:22,UTCTime:23,GeneralizedTime:24,GraphicString:25,VisibleString:26,GeneralString:28,UniversalString:29,CharacterString:30,BMPString:31,Constructor:32,Context:128}});var wo=at((kx,su)=>{"use strict";var ss=require("buffer"),Rr=ss.Buffer,cn={},fn;for(fn in ss)ss.hasOwnProperty(fn)&&(fn==="SlowBuffer"||fn==="Buffer"||(cn[fn]=ss[fn]));var Nr=cn.Buffer={};for(fn in Rr)Rr.hasOwnProperty(fn)&&(fn==="allocUnsafe"||fn==="allocUnsafeSlow"||(Nr[fn]=Rr[fn]));cn.Buffer.prototype=Rr.prototype;(!Nr.from||Nr.from===Uint8Array.from)&&(Nr.from=function(n,t,e){if(typeof n=="number")throw new TypeError('The "value" argument must not be of type number. Received type '+typeof n);if(n&&typeof n.length>"u")throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof n);return Rr(n,t,e)});Nr.alloc||(Nr.alloc=function(n,t,e){if(typeof n!="number")throw new TypeError('The "size" argument must be of type number. Received type '+typeof n);if(n<0||n>=2*(1<<30))throw new RangeError('The value "'+n+'" is invalid for option "size"');var r=Rr(n);return!t||t.length===0?r.fill(0):typeof e=="string"?r.fill(t,e):r.fill(t),r});if(!cn.kStringMaxLength)try{cn.kStringMaxLength=process.binding("buffer").kStringMaxLength}catch{}cn.constants||(cn.constants={MAX_LENGTH:cn.kMaxLength},cn.kStringMaxLength&&(cn.constants.MAX_STRING_LENGTH=cn.kStringMaxLength));su.exports=cn});var cu=at((Bx,au)=>{var og=require("assert"),ou=wo().Buffer,fi=is(),ag=rs(),Pr=ag.newInvalidAsn1Error;function Yt(n){if(!n||!ou.isBuffer(n))throw new TypeError("data must be a node Buffer");this._buf=n,this._size=n.length,this._len=0,this._offset=0}Object.defineProperty(Yt.prototype,"length",{enumerable:!0,get:function(){return this._len}});Object.defineProperty(Yt.prototype,"offset",{enumerable:!0,get:function(){return this._offset}});Object.defineProperty(Yt.prototype,"remain",{get:function(){return this._size-this._offset}});Object.defineProperty(Yt.prototype,"buffer",{get:function(){return this._buf.slice(this._offset)}});Yt.prototype.readByte=function(n){if(this._size-this._offset<1)return null;var t=this._buf[this._offset]&255;return n||(this._offset+=1),t};Yt.prototype.peek=function(){return this.readByte(!0)};Yt.prototype.readLength=function(n){if(n===void 0&&(n=this._offset),n>=this._size)return null;var t=this._buf[n++]&255;if(t===null)return null;if((t&128)===128){if(t&=127,t===0)throw Pr("Indefinite length not supported");if(t>4)throw Pr("encoding too long");if(this._size-n<t)return null;this._len=0;for(var e=0;e<t;e++)this._len=(this._len<<8)+(this._buf[n++]&255)}else this._len=t;return n};Yt.prototype.readSequence=function(n){var t=this.peek();if(t===null)return null;if(n!==void 0&&n!==t)throw Pr("Expected 0x"+n.toString(16)+": got 0x"+t.toString(16));var e=this.readLength(this._offset+1);return e===null?null:(this._offset=e,t)};Yt.prototype.readInt=function(){return this._readTag(fi.Integer)};Yt.prototype.readBoolean=function(){return this._readTag(fi.Boolean)!==0};Yt.prototype.readEnumeration=function(){return this._readTag(fi.Enumeration)};Yt.prototype.readString=function(n,t){n||(n=fi.OctetString);var e=this.peek();if(e===null)return null;if(e!==n)throw Pr("Expected 0x"+n.toString(16)+": got 0x"+e.toString(16));var r=this.readLength(this._offset+1);if(r===null||this.length>this._size-r)return null;if(this._offset=r,this.length===0)return t?ou.alloc(0):"";var s=this._buf.slice(this._offset,this._offset+this.length);return this._offset+=this.length,t?s:s.toString("utf8")};Yt.prototype.readOID=function(n){n||(n=fi.OID);var t=this.readString(n,!0);if(t===null)return null;for(var e=[],r=0,s=0;s<t.length;s++){var i=t[s]&255;r<<=7,r+=i&127,(i&128)===0&&(e.push(r),r=0)}return r=e.shift(),e.unshift(r%40),e.unshift(r/40>>0),e.join(".")};Yt.prototype._readTag=function(n){og.ok(n!==void 0);var t=this.peek();if(t===null)return null;if(t!==n)throw Pr("Expected 0x"+n.toString(16)+": got 0x"+t.toString(16));var e=this.readLength(this._offset+1);if(e===null)return null;if(this.length>4)throw Pr("Integer too long: "+this.length);if(this.length>this._size-e)return null;this._offset=e;for(var r=this._buf[this._offset],s=0,i=0;i<this.length;i++)s<<=8,s|=this._buf[this._offset++]&255;return(r&128)===128&&i!==4&&(s-=1<<i*8),s>>0};au.exports=Yt});var lu=at((Rx,fu)=>{var Qn=require("assert"),os=wo().Buffer,Wn=is(),cg=rs(),as=cg.newInvalidAsn1Error,fg={size:1024,growthFactor:8};function lg(n,t){Qn.ok(n),Qn.equal(typeof n,"object"),Qn.ok(t),Qn.equal(typeof t,"object");var e=Object.getOwnPropertyNames(n);return e.forEach(function(r){if(!t[r]){var s=Object.getOwnPropertyDescriptor(n,r);Object.defineProperty(t,r,s)}}),t}function qt(n){n=lg(fg,n||{}),this._buf=os.alloc(n.size||1024),this._size=this._buf.length,this._offset=0,this._options=n,this._seq=[]}Object.defineProperty(qt.prototype,"buffer",{get:function(){if(this._seq.length)throw as(this._seq.length+" unended sequence(s)");return this._buf.slice(0,this._offset)}});qt.prototype.writeByte=function(n){if(typeof n!="number")throw new TypeError("argument must be a Number");this._ensure(1),this._buf[this._offset++]=n};qt.prototype.writeInt=function(n,t){if(typeof n!="number")throw new TypeError("argument must be a Number");typeof t!="number"&&(t=Wn.Integer);for(var e=4;((n&4286578688)===0||(n&4286578688)===-8388608)&&e>1;)e--,n<<=8;if(e>4)throw as("BER ints cannot be > 0xffffffff");for(this._ensure(2+e),this._buf[this._offset++]=t,this._buf[this._offset++]=e;e-- >0;)this._buf[this._offset++]=(n&4278190080)>>>24,n<<=8};qt.prototype.writeNull=function(){this.writeByte(Wn.Null),this.writeByte(0)};qt.prototype.writeEnumeration=function(n,t){if(typeof n!="number")throw new TypeError("argument must be a Number");return typeof t!="number"&&(t=Wn.Enumeration),this.writeInt(n,t)};qt.prototype.writeBoolean=function(n,t){if(typeof n!="boolean")throw new TypeError("argument must be a Boolean");typeof t!="number"&&(t=Wn.Boolean),this._ensure(3),this._buf[this._offset++]=t,this._buf[this._offset++]=1,this._buf[this._offset++]=n?255:0};qt.prototype.writeString=function(n,t){if(typeof n!="string")throw new TypeError("argument must be a string (was: "+typeof n+")");typeof t!="number"&&(t=Wn.OctetString);var e=os.byteLength(n);this.writeByte(t),this.writeLength(e),e&&(this._ensure(e),this._buf.write(n,this._offset),this._offset+=e)};qt.prototype.writeBuffer=function(n,t){if(typeof t!="number")throw new TypeError("tag must be a number");if(!os.isBuffer(n))throw new TypeError("argument must be a buffer");this.writeByte(t),this.writeLength(n.length),this._ensure(n.length),n.copy(this._buf,this._offset,0,n.length),this._offset+=n.length};qt.prototype.writeStringArray=function(n){if(!n instanceof Array)throw new TypeError("argument must be an Array[String]");var t=this;n.forEach(function(e){t.writeString(e)})};qt.prototype.writeOID=function(n,t){if(typeof n!="string")throw new TypeError("argument must be a string");if(typeof t!="number"&&(t=Wn.OID),!/^([0-9]+\.){3,}[0-9]+$/.test(n))throw new Error("argument is not a valid OID string");function e(o,a){a<128?o.push(a):a<16384?(o.push(a>>>7|128),o.push(a&127)):a<2097152?(o.push(a>>>14|128),o.push((a>>>7|128)&255),o.push(a&127)):a<268435456?(o.push(a>>>21|128),o.push((a>>>14|128)&255),o.push((a>>>7|128)&255),o.push(a&127)):(o.push((a>>>28|128)&255),o.push((a>>>21|128)&255),o.push((a>>>14|128)&255),o.push((a>>>7|128)&255),o.push(a&127))}var r=n.split("."),s=[];s.push(parseInt(r[0],10)*40+parseInt(r[1],10)),r.slice(2).forEach(function(o){e(s,parseInt(o,10))});var i=this;this._ensure(2+s.length),this.writeByte(t),this.writeLength(s.length),s.forEach(function(o){i.writeByte(o)})};qt.prototype.writeLength=function(n){if(typeof n!="number")throw new TypeError("argument must be a Number");if(this._ensure(4),n<=127)this._buf[this._offset++]=n;else if(n<=255)this._buf[this._offset++]=129,this._buf[this._offset++]=n;else if(n<=65535)this._buf[this._offset++]=130,this._buf[this._offset++]=n>>8,this._buf[this._offset++]=n;else if(n<=16777215)this._buf[this._offset++]=131,this._buf[this._offset++]=n>>16,this._buf[this._offset++]=n>>8,this._buf[this._offset++]=n;else throw as("Length too long (> 4 bytes)")};qt.prototype.startSequence=function(n){typeof n!="number"&&(n=Wn.Sequence|Wn.Constructor),this.writeByte(n),this._seq.push(this._offset),this._ensure(3),this._offset+=3};qt.prototype.endSequence=function(){var n=this._seq.pop(),t=n+3,e=this._offset-t;if(e<=127)this._shift(t,e,-2),this._buf[n]=e;else if(e<=255)this._shift(t,e,-1),this._buf[n]=129,this._buf[n+1]=e;else if(e<=65535)this._buf[n]=130,this._buf[n+1]=e>>8,this._buf[n+2]=e;else if(e<=16777215)this._shift(t,e,1),this._buf[n]=131,this._buf[n+1]=e>>16,this._buf[n+2]=e>>8,this._buf[n+3]=e;else throw as("Sequence too long")};qt.prototype._shift=function(n,t,e){Qn.ok(n!==void 0),Qn.ok(t!==void 0),Qn.ok(e),this._buf.copy(this._buf,n+e,n,n+t),this._offset+=e};qt.prototype._ensure=function(n){if(Qn.ok(n),this._size-this._offset<n){var t=this._size*this._options.growthFactor;t-this._offset<n&&(t+=n);var e=os.alloc(t);this._buf.copy(e,0,0,this._offset),this._buf=e,this._size=t}};fu.exports=qt});var uu=at((Nx,ls)=>{var Io=rs(),Co=is(),ug=cu(),dg=lu();ls.exports={Reader:ug,Writer:dg};for(cs in Co)Co.hasOwnProperty(cs)&&(ls.exports[cs]=Co[cs]);var cs;for(fs in Io)Io.hasOwnProperty(fs)&&(ls.exports[fs]=Io[fs]);var fs});var li=at((Px,du)=>{var vo=uu();du.exports={Ber:vo,BerReader:vo.Reader,BerWriter:vo.Writer}});var hu=at((Tx,us)=>{(function(n){"use strict";var t=function(p){var A,m=new Float64Array(16);if(p)for(A=0;A<p.length;A++)m[A]=p[A];return m},e=function(){throw new Error("no PRNG")},r=new Uint8Array(16),s=new Uint8Array(32);s[0]=9;var i=t(),o=t([1]),a=t([56129,1]),c=t([30883,4953,19914,30187,55467,16705,2637,112,59544,30585,16505,36039,65139,11119,27886,20995]),f=t([61785,9906,39828,60374,45398,33411,5274,224,53552,61171,33010,6542,64743,22239,55772,9222]),l=t([54554,36645,11616,51542,42930,38181,51040,26924,56412,64982,57905,49316,21502,52590,14035,8553]),u=t([26200,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214]),h=t([41136,18958,6951,50414,58488,44335,6150,12099,55207,15867,153,11085,57099,20417,9344,11139]);function g(p,A,m,d){p[A]=m>>24&255,p[A+1]=m>>16&255,p[A+2]=m>>8&255,p[A+3]=m&255,p[A+4]=d>>24&255,p[A+5]=d>>16&255,p[A+6]=d>>8&255,p[A+7]=d&255}function y(p,A,m,d,E){var P,$=0;for(P=0;P<E;P++)$|=p[A+P]^m[d+P];return(1&$-1>>>8)-1}function _(p,A,m,d){return y(p,A,m,d,16)}function b(p,A,m,d){return y(p,A,m,d,32)}function C(p,A,m,d){for(var E=d[0]&255|(d[1]&255)<<8|(d[2]&255)<<16|(d[3]&255)<<24,P=m[0]&255|(m[1]&255)<<8|(m[2]&255)<<16|(m[3]&255)<<24,$=m[4]&255|(m[5]&255)<<8|(m[6]&255)<<16|(m[7]&255)<<24,J=m[8]&255|(m[9]&255)<<8|(m[10]&255)<<16|(m[11]&255)<<24,ae=m[12]&255|(m[13]&255)<<8|(m[14]&255)<<16|(m[15]&255)<<24,me=d[4]&255|(d[5]&255)<<8|(d[6]&255)<<16|(d[7]&255)<<24,he=A[0]&255|(A[1]&255)<<8|(A[2]&255)<<16|(A[3]&255)<<24,tt=A[4]&255|(A[5]&255)<<8|(A[6]&255)<<16|(A[7]&255)<<24,ge=A[8]&255|(A[9]&255)<<8|(A[10]&255)<<16|(A[11]&255)<<24,Te=A[12]&255|(A[13]&255)<<8|(A[14]&255)<<16|(A[15]&255)<<24,Le=d[8]&255|(d[9]&255)<<8|(d[10]&255)<<16|(d[11]&255)<<24,Fe=m[16]&255|(m[17]&255)<<8|(m[18]&255)<<16|(m[19]&255)<<24,Me=m[20]&255|(m[21]&255)<<8|(m[22]&255)<<16|(m[23]&255)<<24,Ue=m[24]&255|(m[25]&255)<<8|(m[26]&255)<<16|(m[27]&255)<<24,Oe=m[28]&255|(m[29]&255)<<8|(m[30]&255)<<16|(m[31]&255)<<24,De=d[12]&255|(d[13]&255)<<8|(d[14]&255)<<16|(d[15]&255)<<24,Ae=E,be=P,pe=$,Ee=J,_e=ae,de=me,Q=he,W=tt,ie=ge,j=Te,Z=Le,oe=Fe,Ce=Me,He=Ue,We=Oe,Qe=De,S,Ke=0;Ke<20;Ke+=2)S=Ae+Ce|0,_e^=S<<7|S>>>25,S=_e+Ae|0,ie^=S<<9|S>>>23,S=ie+_e|0,Ce^=S<<13|S>>>19,S=Ce+ie|0,Ae^=S<<18|S>>>14,S=de+be|0,j^=S<<7|S>>>25,S=j+de|0,He^=S<<9|S>>>23,S=He+j|0,be^=S<<13|S>>>19,S=be+He|0,de^=S<<18|S>>>14,S=Z+Q|0,We^=S<<7|S>>>25,S=We+Z|0,pe^=S<<9|S>>>23,S=pe+We|0,Q^=S<<13|S>>>19,S=Q+pe|0,Z^=S<<18|S>>>14,S=Qe+oe|0,Ee^=S<<7|S>>>25,S=Ee+Qe|0,W^=S<<9|S>>>23,S=W+Ee|0,oe^=S<<13|S>>>19,S=oe+W|0,Qe^=S<<18|S>>>14,S=Ae+Ee|0,be^=S<<7|S>>>25,S=be+Ae|0,pe^=S<<9|S>>>23,S=pe+be|0,Ee^=S<<13|S>>>19,S=Ee+pe|0,Ae^=S<<18|S>>>14,S=de+_e|0,Q^=S<<7|S>>>25,S=Q+de|0,W^=S<<9|S>>>23,S=W+Q|0,_e^=S<<13|S>>>19,S=_e+W|0,de^=S<<18|S>>>14,S=Z+j|0,oe^=S<<7|S>>>25,S=oe+Z|0,ie^=S<<9|S>>>23,S=ie+oe|0,j^=S<<13|S>>>19,S=j+ie|0,Z^=S<<18|S>>>14,S=Qe+We|0,Ce^=S<<7|S>>>25,S=Ce+Qe|0,He^=S<<9|S>>>23,S=He+Ce|0,We^=S<<13|S>>>19,S=We+He|0,Qe^=S<<18|S>>>14;Ae=Ae+E|0,be=be+P|0,pe=pe+$|0,Ee=Ee+J|0,_e=_e+ae|0,de=de+me|0,Q=Q+he|0,W=W+tt|0,ie=ie+ge|0,j=j+Te|0,Z=Z+Le|0,oe=oe+Fe|0,Ce=Ce+Me|0,He=He+Ue|0,We=We+Oe|0,Qe=Qe+De|0,p[0]=Ae>>>0&255,p[1]=Ae>>>8&255,p[2]=Ae>>>16&255,p[3]=Ae>>>24&255,p[4]=be>>>0&255,p[5]=be>>>8&255,p[6]=be>>>16&255,p[7]=be>>>24&255,p[8]=pe>>>0&255,p[9]=pe>>>8&255,p[10]=pe>>>16&255,p[11]=pe>>>24&255,p[12]=Ee>>>0&255,p[13]=Ee>>>8&255,p[14]=Ee>>>16&255,p[15]=Ee>>>24&255,p[16]=_e>>>0&255,p[17]=_e>>>8&255,p[18]=_e>>>16&255,p[19]=_e>>>24&255,p[20]=de>>>0&255,p[21]=de>>>8&255,p[22]=de>>>16&255,p[23]=de>>>24&255,p[24]=Q>>>0&255,p[25]=Q>>>8&255,p[26]=Q>>>16&255,p[27]=Q>>>24&255,p[28]=W>>>0&255,p[29]=W>>>8&255,p[30]=W>>>16&255,p[31]=W>>>24&255,p[32]=ie>>>0&255,p[33]=ie>>>8&255,p[34]=ie>>>16&255,p[35]=ie>>>24&255,p[36]=j>>>0&255,p[37]=j>>>8&255,p[38]=j>>>16&255,p[39]=j>>>24&255,p[40]=Z>>>0&255,p[41]=Z>>>8&255,p[42]=Z>>>16&255,p[43]=Z>>>24&255,p[44]=oe>>>0&255,p[45]=oe>>>8&255,p[46]=oe>>>16&255,p[47]=oe>>>24&255,p[48]=Ce>>>0&255,p[49]=Ce>>>8&255,p[50]=Ce>>>16&255,p[51]=Ce>>>24&255,p[52]=He>>>0&255,p[53]=He>>>8&255,p[54]=He>>>16&255,p[55]=He>>>24&255,p[56]=We>>>0&255,p[57]=We>>>8&255,p[58]=We>>>16&255,p[59]=We>>>24&255,p[60]=Qe>>>0&255,p[61]=Qe>>>8&255,p[62]=Qe>>>16&255,p[63]=Qe>>>24&255}function L(p,A,m,d){for(var E=d[0]&255|(d[1]&255)<<8|(d[2]&255)<<16|(d[3]&255)<<24,P=m[0]&255|(m[1]&255)<<8|(m[2]&255)<<16|(m[3]&255)<<24,$=m[4]&255|(m[5]&255)<<8|(m[6]&255)<<16|(m[7]&255)<<24,J=m[8]&255|(m[9]&255)<<8|(m[10]&255)<<16|(m[11]&255)<<24,ae=m[12]&255|(m[13]&255)<<8|(m[14]&255)<<16|(m[15]&255)<<24,me=d[4]&255|(d[5]&255)<<8|(d[6]&255)<<16|(d[7]&255)<<24,he=A[0]&255|(A[1]&255)<<8|(A[2]&255)<<16|(A[3]&255)<<24,tt=A[4]&255|(A[5]&255)<<8|(A[6]&255)<<16|(A[7]&255)<<24,ge=A[8]&255|(A[9]&255)<<8|(A[10]&255)<<16|(A[11]&255)<<24,Te=A[12]&255|(A[13]&255)<<8|(A[14]&255)<<16|(A[15]&255)<<24,Le=d[8]&255|(d[9]&255)<<8|(d[10]&255)<<16|(d[11]&255)<<24,Fe=m[16]&255|(m[17]&255)<<8|(m[18]&255)<<16|(m[19]&255)<<24,Me=m[20]&255|(m[21]&255)<<8|(m[22]&255)<<16|(m[23]&255)<<24,Ue=m[24]&255|(m[25]&255)<<8|(m[26]&255)<<16|(m[27]&255)<<24,Oe=m[28]&255|(m[29]&255)<<8|(m[30]&255)<<16|(m[31]&255)<<24,De=d[12]&255|(d[13]&255)<<8|(d[14]&255)<<16|(d[15]&255)<<24,Ae=E,be=P,pe=$,Ee=J,_e=ae,de=me,Q=he,W=tt,ie=ge,j=Te,Z=Le,oe=Fe,Ce=Me,He=Ue,We=Oe,Qe=De,S,Ke=0;Ke<20;Ke+=2)S=Ae+Ce|0,_e^=S<<7|S>>>25,S=_e+Ae|0,ie^=S<<9|S>>>23,S=ie+_e|0,Ce^=S<<13|S>>>19,S=Ce+ie|0,Ae^=S<<18|S>>>14,S=de+be|0,j^=S<<7|S>>>25,S=j+de|0,He^=S<<9|S>>>23,S=He+j|0,be^=S<<13|S>>>19,S=be+He|0,de^=S<<18|S>>>14,S=Z+Q|0,We^=S<<7|S>>>25,S=We+Z|0,pe^=S<<9|S>>>23,S=pe+We|0,Q^=S<<13|S>>>19,S=Q+pe|0,Z^=S<<18|S>>>14,S=Qe+oe|0,Ee^=S<<7|S>>>25,S=Ee+Qe|0,W^=S<<9|S>>>23,S=W+Ee|0,oe^=S<<13|S>>>19,S=oe+W|0,Qe^=S<<18|S>>>14,S=Ae+Ee|0,be^=S<<7|S>>>25,S=be+Ae|0,pe^=S<<9|S>>>23,S=pe+be|0,Ee^=S<<13|S>>>19,S=Ee+pe|0,Ae^=S<<18|S>>>14,S=de+_e|0,Q^=S<<7|S>>>25,S=Q+de|0,W^=S<<9|S>>>23,S=W+Q|0,_e^=S<<13|S>>>19,S=_e+W|0,de^=S<<18|S>>>14,S=Z+j|0,oe^=S<<7|S>>>25,S=oe+Z|0,ie^=S<<9|S>>>23,S=ie+oe|0,j^=S<<13|S>>>19,S=j+ie|0,Z^=S<<18|S>>>14,S=Qe+We|0,Ce^=S<<7|S>>>25,S=Ce+Qe|0,He^=S<<9|S>>>23,S=He+Ce|0,We^=S<<13|S>>>19,S=We+He|0,Qe^=S<<18|S>>>14;p[0]=Ae>>>0&255,p[1]=Ae>>>8&255,p[2]=Ae>>>16&255,p[3]=Ae>>>24&255,p[4]=de>>>0&255,p[5]=de>>>8&255,p[6]=de>>>16&255,p[7]=de>>>24&255,p[8]=Z>>>0&255,p[9]=Z>>>8&255,p[10]=Z>>>16&255,p[11]=Z>>>24&255,p[12]=Qe>>>0&255,p[13]=Qe>>>8&255,p[14]=Qe>>>16&255,p[15]=Qe>>>24&255,p[16]=Q>>>0&255,p[17]=Q>>>8&255,p[18]=Q>>>16&255,p[19]=Q>>>24&255,p[20]=W>>>0&255,p[21]=W>>>8&255,p[22]=W>>>16&255,p[23]=W>>>24&255,p[24]=ie>>>0&255,p[25]=ie>>>8&255,p[26]=ie>>>16&255,p[27]=ie>>>24&255,p[28]=j>>>0&255,p[29]=j>>>8&255,p[30]=j>>>16&255,p[31]=j>>>24&255}function F(p,A,m,d){C(p,A,m,d)}function k(p,A,m,d){L(p,A,m,d)}var K=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function ee(p,A,m,d,E,P,$){var J=new Uint8Array(16),ae=new Uint8Array(64),me,he;for(he=0;he<16;he++)J[he]=0;for(he=0;he<8;he++)J[he]=P[he];for(;E>=64;){for(F(ae,J,$,K),he=0;he<64;he++)p[A+he]=m[d+he]^ae[he];for(me=1,he=8;he<16;he++)me=me+(J[he]&255)|0,J[he]=me&255,me>>>=8;E-=64,A+=64,d+=64}if(E>0)for(F(ae,J,$,K),he=0;he<E;he++)p[A+he]=m[d+he]^ae[he];return 0}function O(p,A,m,d,E){var P=new Uint8Array(16),$=new Uint8Array(64),J,ae;for(ae=0;ae<16;ae++)P[ae]=0;for(ae=0;ae<8;ae++)P[ae]=d[ae];for(;m>=64;){for(F($,P,E,K),ae=0;ae<64;ae++)p[A+ae]=$[ae];for(J=1,ae=8;ae<16;ae++)J=J+(P[ae]&255)|0,P[ae]=J&255,J>>>=8;m-=64,A+=64}if(m>0)for(F($,P,E,K),ae=0;ae<m;ae++)p[A+ae]=$[ae];return 0}function x(p,A,m,d,E){var P=new Uint8Array(32);k(P,d,E,K);for(var $=new Uint8Array(8),J=0;J<8;J++)$[J]=d[J+16];return O(p,A,m,$,P)}function w(p,A,m,d,E,P,$){var J=new Uint8Array(32);k(J,P,$,K);for(var ae=new Uint8Array(8),me=0;me<8;me++)ae[me]=P[me+16];return ee(p,A,m,d,E,ae,J)}var I=function(p){this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.leftover=0,this.fin=0;var A,m,d,E,P,$,J,ae;A=p[0]&255|(p[1]&255)<<8,this.r[0]=A&8191,m=p[2]&255|(p[3]&255)<<8,this.r[1]=(A>>>13|m<<3)&8191,d=p[4]&255|(p[5]&255)<<8,this.r[2]=(m>>>10|d<<6)&7939,E=p[6]&255|(p[7]&255)<<8,this.r[3]=(d>>>7|E<<9)&8191,P=p[8]&255|(p[9]&255)<<8,this.r[4]=(E>>>4|P<<12)&255,this.r[5]=P>>>1&8190,$=p[10]&255|(p[11]&255)<<8,this.r[6]=(P>>>14|$<<2)&8191,J=p[12]&255|(p[13]&255)<<8,this.r[7]=($>>>11|J<<5)&8065,ae=p[14]&255|(p[15]&255)<<8,this.r[8]=(J>>>8|ae<<8)&8191,this.r[9]=ae>>>5&127,this.pad[0]=p[16]&255|(p[17]&255)<<8,this.pad[1]=p[18]&255|(p[19]&255)<<8,this.pad[2]=p[20]&255|(p[21]&255)<<8,this.pad[3]=p[22]&255|(p[23]&255)<<8,this.pad[4]=p[24]&255|(p[25]&255)<<8,this.pad[5]=p[26]&255|(p[27]&255)<<8,this.pad[6]=p[28]&255|(p[29]&255)<<8,this.pad[7]=p[30]&255|(p[31]&255)<<8};I.prototype.blocks=function(p,A,m){for(var d=this.fin?0:2048,E,P,$,J,ae,me,he,tt,ge,Te,Le,Fe,Me,Ue,Oe,De,Ae,be,pe,Ee=this.h[0],_e=this.h[1],de=this.h[2],Q=this.h[3],W=this.h[4],ie=this.h[5],j=this.h[6],Z=this.h[7],oe=this.h[8],Ce=this.h[9],He=this.r[0],We=this.r[1],Qe=this.r[2],S=this.r[3],Ke=this.r[4],nt=this.r[5],rt=this.r[6],qe=this.r[7],Je=this.r[8],Ze=this.r[9];m>=16;)E=p[A+0]&255|(p[A+1]&255)<<8,Ee+=E&8191,P=p[A+2]&255|(p[A+3]&255)<<8,_e+=(E>>>13|P<<3)&8191,$=p[A+4]&255|(p[A+5]&255)<<8,de+=(P>>>10|$<<6)&8191,J=p[A+6]&255|(p[A+7]&255)<<8,Q+=($>>>7|J<<9)&8191,ae=p[A+8]&255|(p[A+9]&255)<<8,W+=(J>>>4|ae<<12)&8191,ie+=ae>>>1&8191,me=p[A+10]&255|(p[A+11]&255)<<8,j+=(ae>>>14|me<<2)&8191,he=p[A+12]&255|(p[A+13]&255)<<8,Z+=(me>>>11|he<<5)&8191,tt=p[A+14]&255|(p[A+15]&255)<<8,oe+=(he>>>8|tt<<8)&8191,Ce+=tt>>>5|d,ge=0,Te=ge,Te+=Ee*He,Te+=_e*(5*Ze),Te+=de*(5*Je),Te+=Q*(5*qe),Te+=W*(5*rt),ge=Te>>>13,Te&=8191,Te+=ie*(5*nt),Te+=j*(5*Ke),Te+=Z*(5*S),Te+=oe*(5*Qe),Te+=Ce*(5*We),ge+=Te>>>13,Te&=8191,Le=ge,Le+=Ee*We,Le+=_e*He,Le+=de*(5*Ze),Le+=Q*(5*Je),Le+=W*(5*qe),ge=Le>>>13,Le&=8191,Le+=ie*(5*rt),Le+=j*(5*nt),Le+=Z*(5*Ke),Le+=oe*(5*S),Le+=Ce*(5*Qe),ge+=Le>>>13,Le&=8191,Fe=ge,Fe+=Ee*Qe,Fe+=_e*We,Fe+=de*He,Fe+=Q*(5*Ze),Fe+=W*(5*Je),ge=Fe>>>13,Fe&=8191,Fe+=ie*(5*qe),Fe+=j*(5*rt),Fe+=Z*(5*nt),Fe+=oe*(5*Ke),Fe+=Ce*(5*S),ge+=Fe>>>13,Fe&=8191,Me=ge,Me+=Ee*S,Me+=_e*Qe,Me+=de*We,Me+=Q*He,Me+=W*(5*Ze),ge=Me>>>13,Me&=8191,Me+=ie*(5*Je),Me+=j*(5*qe),Me+=Z*(5*rt),Me+=oe*(5*nt),Me+=Ce*(5*Ke),ge+=Me>>>13,Me&=8191,Ue=ge,Ue+=Ee*Ke,Ue+=_e*S,Ue+=de*Qe,Ue+=Q*We,Ue+=W*He,ge=Ue>>>13,Ue&=8191,Ue+=ie*(5*Ze),Ue+=j*(5*Je),Ue+=Z*(5*qe),Ue+=oe*(5*rt),Ue+=Ce*(5*nt),ge+=Ue>>>13,Ue&=8191,Oe=ge,Oe+=Ee*nt,Oe+=_e*Ke,Oe+=de*S,Oe+=Q*Qe,Oe+=W*We,ge=Oe>>>13,Oe&=8191,Oe+=ie*He,Oe+=j*(5*Ze),Oe+=Z*(5*Je),Oe+=oe*(5*qe),Oe+=Ce*(5*rt),ge+=Oe>>>13,Oe&=8191,De=ge,De+=Ee*rt,De+=_e*nt,De+=de*Ke,De+=Q*S,De+=W*Qe,ge=De>>>13,De&=8191,De+=ie*We,De+=j*He,De+=Z*(5*Ze),De+=oe*(5*Je),De+=Ce*(5*qe),ge+=De>>>13,De&=8191,Ae=ge,Ae+=Ee*qe,Ae+=_e*rt,Ae+=de*nt,Ae+=Q*Ke,Ae+=W*S,ge=Ae>>>13,Ae&=8191,Ae+=ie*Qe,Ae+=j*We,Ae+=Z*He,Ae+=oe*(5*Ze),Ae+=Ce*(5*Je),ge+=Ae>>>13,Ae&=8191,be=ge,be+=Ee*Je,be+=_e*qe,be+=de*rt,be+=Q*nt,be+=W*Ke,ge=be>>>13,be&=8191,be+=ie*S,be+=j*Qe,be+=Z*We,be+=oe*He,be+=Ce*(5*Ze),ge+=be>>>13,be&=8191,pe=ge,pe+=Ee*Ze,pe+=_e*Je,pe+=de*qe,pe+=Q*rt,pe+=W*nt,ge=pe>>>13,pe&=8191,pe+=ie*Ke,pe+=j*S,pe+=Z*Qe,pe+=oe*We,pe+=Ce*He,ge+=pe>>>13,pe&=8191,ge=(ge<<2)+ge|0,ge=ge+Te|0,Te=ge&8191,ge=ge>>>13,Le+=ge,Ee=Te,_e=Le,de=Fe,Q=Me,W=Ue,ie=Oe,j=De,Z=Ae,oe=be,Ce=pe,A+=16,m-=16;this.h[0]=Ee,this.h[1]=_e,this.h[2]=de,this.h[3]=Q,this.h[4]=W,this.h[5]=ie,this.h[6]=j,this.h[7]=Z,this.h[8]=oe,this.h[9]=Ce},I.prototype.finish=function(p,A){var m=new Uint16Array(10),d,E,P,$;if(this.leftover){for($=this.leftover,this.buffer[$++]=1;$<16;$++)this.buffer[$]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(d=this.h[1]>>>13,this.h[1]&=8191,$=2;$<10;$++)this.h[$]+=d,d=this.h[$]>>>13,this.h[$]&=8191;for(this.h[0]+=d*5,d=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=d,d=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=d,m[0]=this.h[0]+5,d=m[0]>>>13,m[0]&=8191,$=1;$<10;$++)m[$]=this.h[$]+d,d=m[$]>>>13,m[$]&=8191;for(m[9]-=8192,E=(d^1)-1,$=0;$<10;$++)m[$]&=E;for(E=~E,$=0;$<10;$++)this.h[$]=this.h[$]&E|m[$];for(this.h[0]=(this.h[0]|this.h[1]<<13)&65535,this.h[1]=(this.h[1]>>>3|this.h[2]<<10)&65535,this.h[2]=(this.h[2]>>>6|this.h[3]<<7)&65535,this.h[3]=(this.h[3]>>>9|this.h[4]<<4)&65535,this.h[4]=(this.h[4]>>>12|this.h[5]<<1|this.h[6]<<14)&65535,this.h[5]=(this.h[6]>>>2|this.h[7]<<11)&65535,this.h[6]=(this.h[7]>>>5|this.h[8]<<8)&65535,this.h[7]=(this.h[8]>>>8|this.h[9]<<5)&65535,P=this.h[0]+this.pad[0],this.h[0]=P&65535,$=1;$<8;$++)P=(this.h[$]+this.pad[$]|0)+(P>>>16)|0,this.h[$]=P&65535;p[A+0]=this.h[0]>>>0&255,p[A+1]=this.h[0]>>>8&255,p[A+2]=this.h[1]>>>0&255,p[A+3]=this.h[1]>>>8&255,p[A+4]=this.h[2]>>>0&255,p[A+5]=this.h[2]>>>8&255,p[A+6]=this.h[3]>>>0&255,p[A+7]=this.h[3]>>>8&255,p[A+8]=this.h[4]>>>0&255,p[A+9]=this.h[4]>>>8&255,p[A+10]=this.h[5]>>>0&255,p[A+11]=this.h[5]>>>8&255,p[A+12]=this.h[6]>>>0&255,p[A+13]=this.h[6]>>>8&255,p[A+14]=this.h[7]>>>0&255,p[A+15]=this.h[7]>>>8&255},I.prototype.update=function(p,A,m){var d,E;if(this.leftover){for(E=16-this.leftover,E>m&&(E=m),d=0;d<E;d++)this.buffer[this.leftover+d]=p[A+d];if(m-=E,A+=E,this.leftover+=E,this.leftover<16)return;this.blocks(this.buffer,0,16),this.leftover=0}if(m>=16&&(E=m-m%16,this.blocks(p,A,E),A+=E,m-=E),m){for(d=0;d<m;d++)this.buffer[this.leftover+d]=p[A+d];this.leftover+=m}};function U(p,A,m,d,E,P){var $=new I(P);return $.update(m,d,E),$.finish(p,A),0}function R(p,A,m,d,E,P){var $=new Uint8Array(16);return U($,0,m,d,E,P),_(p,A,$,0)}function re(p,A,m,d,E){var P;if(m<32)return-1;for(w(p,0,A,0,m,d,E),U(p,16,p,32,m-32,p),P=0;P<16;P++)p[P]=0;return 0}function G(p,A,m,d,E){var P,$=new Uint8Array(32);if(m<32||(x($,0,32,d,E),R(A,16,A,32,m-32,$)!==0))return-1;for(w(p,0,A,0,m,d,E),P=0;P<32;P++)p[P]=0;return 0}function Y(p,A){var m;for(m=0;m<16;m++)p[m]=A[m]|0}function te(p){var A,m,d=1;for(A=0;A<16;A++)m=p[A]+d+65535,d=Math.floor(m/65536),p[A]=m-d*65536;p[0]+=d-1+37*(d-1)}function ce(p,A,m){for(var d,E=~(m-1),P=0;P<16;P++)d=E&(p[P]^A[P]),p[P]^=d,A[P]^=d}function D(p,A){var m,d,E,P=t(),$=t();for(m=0;m<16;m++)$[m]=A[m];for(te($),te($),te($),d=0;d<2;d++){for(P[0]=$[0]-65517,m=1;m<15;m++)P[m]=$[m]-65535-(P[m-1]>>16&1),P[m-1]&=65535;P[15]=$[15]-32767-(P[14]>>16&1),E=P[15]>>16&1,P[14]&=65535,ce($,P,1-E)}for(m=0;m<16;m++)p[2*m]=$[m]&255,p[2*m+1]=$[m]>>8}function v(p,A){var m=new Uint8Array(32),d=new Uint8Array(32);return D(m,p),D(d,A),b(m,0,d,0)}function N(p){var A=new Uint8Array(32);return D(A,p),A[0]&1}function H(p,A){var m;for(m=0;m<16;m++)p[m]=A[2*m]+(A[2*m+1]<<8);p[15]&=32767}function X(p,A,m){for(var d=0;d<16;d++)p[d]=A[d]+m[d]}function fe(p,A,m){for(var d=0;d<16;d++)p[d]=A[d]-m[d]}function se(p,A,m){var d,E,P=0,$=0,J=0,ae=0,me=0,he=0,tt=0,ge=0,Te=0,Le=0,Fe=0,Me=0,Ue=0,Oe=0,De=0,Ae=0,be=0,pe=0,Ee=0,_e=0,de=0,Q=0,W=0,ie=0,j=0,Z=0,oe=0,Ce=0,He=0,We=0,Qe=0,S=m[0],Ke=m[1],nt=m[2],rt=m[3],qe=m[4],Je=m[5],Ze=m[6],Ct=m[7],ct=m[8],St=m[9],wt=m[10],It=m[11],Lt=m[12],Ht=m[13],Qt=m[14],Wt=m[15];d=A[0],P+=d*S,$+=d*Ke,J+=d*nt,ae+=d*rt,me+=d*qe,he+=d*Je,tt+=d*Ze,ge+=d*Ct,Te+=d*ct,Le+=d*St,Fe+=d*wt,Me+=d*It,Ue+=d*Lt,Oe+=d*Ht,De+=d*Qt,Ae+=d*Wt,d=A[1],$+=d*S,J+=d*Ke,ae+=d*nt,me+=d*rt,he+=d*qe,tt+=d*Je,ge+=d*Ze,Te+=d*Ct,Le+=d*ct,Fe+=d*St,Me+=d*wt,Ue+=d*It,Oe+=d*Lt,De+=d*Ht,Ae+=d*Qt,be+=d*Wt,d=A[2],J+=d*S,ae+=d*Ke,me+=d*nt,he+=d*rt,tt+=d*qe,ge+=d*Je,Te+=d*Ze,Le+=d*Ct,Fe+=d*ct,Me+=d*St,Ue+=d*wt,Oe+=d*It,De+=d*Lt,Ae+=d*Ht,be+=d*Qt,pe+=d*Wt,d=A[3],ae+=d*S,me+=d*Ke,he+=d*nt,tt+=d*rt,ge+=d*qe,Te+=d*Je,Le+=d*Ze,Fe+=d*Ct,Me+=d*ct,Ue+=d*St,Oe+=d*wt,De+=d*It,Ae+=d*Lt,be+=d*Ht,pe+=d*Qt,Ee+=d*Wt,d=A[4],me+=d*S,he+=d*Ke,tt+=d*nt,ge+=d*rt,Te+=d*qe,Le+=d*Je,Fe+=d*Ze,Me+=d*Ct,Ue+=d*ct,Oe+=d*St,De+=d*wt,Ae+=d*It,be+=d*Lt,pe+=d*Ht,Ee+=d*Qt,_e+=d*Wt,d=A[5],he+=d*S,tt+=d*Ke,ge+=d*nt,Te+=d*rt,Le+=d*qe,Fe+=d*Je,Me+=d*Ze,Ue+=d*Ct,Oe+=d*ct,De+=d*St,Ae+=d*wt,be+=d*It,pe+=d*Lt,Ee+=d*Ht,_e+=d*Qt,de+=d*Wt,d=A[6],tt+=d*S,ge+=d*Ke,Te+=d*nt,Le+=d*rt,Fe+=d*qe,Me+=d*Je,Ue+=d*Ze,Oe+=d*Ct,De+=d*ct,Ae+=d*St,be+=d*wt,pe+=d*It,Ee+=d*Lt,_e+=d*Ht,de+=d*Qt,Q+=d*Wt,d=A[7],ge+=d*S,Te+=d*Ke,Le+=d*nt,Fe+=d*rt,Me+=d*qe,Ue+=d*Je,Oe+=d*Ze,De+=d*Ct,Ae+=d*ct,be+=d*St,pe+=d*wt,Ee+=d*It,_e+=d*Lt,de+=d*Ht,Q+=d*Qt,W+=d*Wt,d=A[8],Te+=d*S,Le+=d*Ke,Fe+=d*nt,Me+=d*rt,Ue+=d*qe,Oe+=d*Je,De+=d*Ze,Ae+=d*Ct,be+=d*ct,pe+=d*St,Ee+=d*wt,_e+=d*It,de+=d*Lt,Q+=d*Ht,W+=d*Qt,ie+=d*Wt,d=A[9],Le+=d*S,Fe+=d*Ke,Me+=d*nt,Ue+=d*rt,Oe+=d*qe,De+=d*Je,Ae+=d*Ze,be+=d*Ct,pe+=d*ct,Ee+=d*St,_e+=d*wt,de+=d*It,Q+=d*Lt,W+=d*Ht,ie+=d*Qt,j+=d*Wt,d=A[10],Fe+=d*S,Me+=d*Ke,Ue+=d*nt,Oe+=d*rt,De+=d*qe,Ae+=d*Je,be+=d*Ze,pe+=d*Ct,Ee+=d*ct,_e+=d*St,de+=d*wt,Q+=d*It,W+=d*Lt,ie+=d*Ht,j+=d*Qt,Z+=d*Wt,d=A[11],Me+=d*S,Ue+=d*Ke,Oe+=d*nt,De+=d*rt,Ae+=d*qe,be+=d*Je,pe+=d*Ze,Ee+=d*Ct,_e+=d*ct,de+=d*St,Q+=d*wt,W+=d*It,ie+=d*Lt,j+=d*Ht,Z+=d*Qt,oe+=d*Wt,d=A[12],Ue+=d*S,Oe+=d*Ke,De+=d*nt,Ae+=d*rt,be+=d*qe,pe+=d*Je,Ee+=d*Ze,_e+=d*Ct,de+=d*ct,Q+=d*St,W+=d*wt,ie+=d*It,j+=d*Lt,Z+=d*Ht,oe+=d*Qt,Ce+=d*Wt,d=A[13],Oe+=d*S,De+=d*Ke,Ae+=d*nt,be+=d*rt,pe+=d*qe,Ee+=d*Je,_e+=d*Ze,de+=d*Ct,Q+=d*ct,W+=d*St,ie+=d*wt,j+=d*It,Z+=d*Lt,oe+=d*Ht,Ce+=d*Qt,He+=d*Wt,d=A[14],De+=d*S,Ae+=d*Ke,be+=d*nt,pe+=d*rt,Ee+=d*qe,_e+=d*Je,de+=d*Ze,Q+=d*Ct,W+=d*ct,ie+=d*St,j+=d*wt,Z+=d*It,oe+=d*Lt,Ce+=d*Ht,He+=d*Qt,We+=d*Wt,d=A[15],Ae+=d*S,be+=d*Ke,pe+=d*nt,Ee+=d*rt,_e+=d*qe,de+=d*Je,Q+=d*Ze,W+=d*Ct,ie+=d*ct,j+=d*St,Z+=d*wt,oe+=d*It,Ce+=d*Lt,He+=d*Ht,We+=d*Qt,Qe+=d*Wt,P+=38*be,$+=38*pe,J+=38*Ee,ae+=38*_e,me+=38*de,he+=38*Q,tt+=38*W,ge+=38*ie,Te+=38*j,Le+=38*Z,Fe+=38*oe,Me+=38*Ce,Ue+=38*He,Oe+=38*We,De+=38*Qe,E=1,d=P+E+65535,E=Math.floor(d/65536),P=d-E*65536,d=$+E+65535,E=Math.floor(d/65536),$=d-E*65536,d=J+E+65535,E=Math.floor(d/65536),J=d-E*65536,d=ae+E+65535,E=Math.floor(d/65536),ae=d-E*65536,d=me+E+65535,E=Math.floor(d/65536),me=d-E*65536,d=he+E+65535,E=Math.floor(d/65536),he=d-E*65536,d=tt+E+65535,E=Math.floor(d/65536),tt=d-E*65536,d=ge+E+65535,E=Math.floor(d/65536),ge=d-E*65536,d=Te+E+65535,E=Math.floor(d/65536),Te=d-E*65536,d=Le+E+65535,E=Math.floor(d/65536),Le=d-E*65536,d=Fe+E+65535,E=Math.floor(d/65536),Fe=d-E*65536,d=Me+E+65535,E=Math.floor(d/65536),Me=d-E*65536,d=Ue+E+65535,E=Math.floor(d/65536),Ue=d-E*65536,d=Oe+E+65535,E=Math.floor(d/65536),Oe=d-E*65536,d=De+E+65535,E=Math.floor(d/65536),De=d-E*65536,d=Ae+E+65535,E=Math.floor(d/65536),Ae=d-E*65536,P+=E-1+37*(E-1),E=1,d=P+E+65535,E=Math.floor(d/65536),P=d-E*65536,d=$+E+65535,E=Math.floor(d/65536),$=d-E*65536,d=J+E+65535,E=Math.floor(d/65536),J=d-E*65536,d=ae+E+65535,E=Math.floor(d/65536),ae=d-E*65536,d=me+E+65535,E=Math.floor(d/65536),me=d-E*65536,d=he+E+65535,E=Math.floor(d/65536),he=d-E*65536,d=tt+E+65535,E=Math.floor(d/65536),tt=d-E*65536,d=ge+E+65535,E=Math.floor(d/65536),ge=d-E*65536,d=Te+E+65535,E=Math.floor(d/65536),Te=d-E*65536,d=Le+E+65535,E=Math.floor(d/65536),Le=d-E*65536,d=Fe+E+65535,E=Math.floor(d/65536),Fe=d-E*65536,d=Me+E+65535,E=Math.floor(d/65536),Me=d-E*65536,d=Ue+E+65535,E=Math.floor(d/65536),Ue=d-E*65536,d=Oe+E+65535,E=Math.floor(d/65536),Oe=d-E*65536,d=De+E+65535,E=Math.floor(d/65536),De=d-E*65536,d=Ae+E+65535,E=Math.floor(d/65536),Ae=d-E*65536,P+=E-1+37*(E-1),p[0]=P,p[1]=$,p[2]=J,p[3]=ae,p[4]=me,p[5]=he,p[6]=tt,p[7]=ge,p[8]=Te,p[9]=Le,p[10]=Fe,p[11]=Me,p[12]=Ue,p[13]=Oe,p[14]=De,p[15]=Ae}function ze(p,A){se(p,A,A)}function _t(p,A){var m=t(),d;for(d=0;d<16;d++)m[d]=A[d];for(d=253;d>=0;d--)ze(m,m),d!==2&&d!==4&&se(m,m,A);for(d=0;d<16;d++)p[d]=m[d]}function An(p,A){var m=t(),d;for(d=0;d<16;d++)m[d]=A[d];for(d=250;d>=0;d--)ze(m,m),d!==1&&se(m,m,A);for(d=0;d<16;d++)p[d]=m[d]}function pr(p,A,m){var d=new Uint8Array(32),E=new Float64Array(80),P,$,J=t(),ae=t(),me=t(),he=t(),tt=t(),ge=t();for($=0;$<31;$++)d[$]=A[$];for(d[31]=A[31]&127|64,d[0]&=248,H(E,m),$=0;$<16;$++)ae[$]=E[$],he[$]=J[$]=me[$]=0;for(J[0]=he[0]=1,$=254;$>=0;--$)P=d[$>>>3]>>>($&7)&1,ce(J,ae,P),ce(me,he,P),X(tt,J,me),fe(J,J,me),X(me,ae,he),fe(ae,ae,he),ze(he,tt),ze(ge,J),se(J,me,J),se(me,ae,tt),X(tt,J,me),fe(J,J,me),ze(ae,J),fe(me,he,ge),se(J,me,a),X(J,J,he),se(me,me,J),se(J,he,ge),se(he,ae,E),ze(ae,tt),ce(J,ae,P),ce(me,he,P);for($=0;$<16;$++)E[$+16]=J[$],E[$+32]=me[$],E[$+48]=ae[$],E[$+64]=he[$];var Te=E.subarray(32),Le=E.subarray(16);return _t(Te,Te),se(Le,Le,Te),D(p,Le),0}function gr(p,A){return pr(p,A,s)}function kn(p,A){return e(A,32),gr(p,A)}function mr(p,A,m){var d=new Uint8Array(32);return pr(d,m,A),k(p,r,d,K)}var jr=re,Mi=G;function Xr(p,A,m,d,E,P){var $=new Uint8Array(32);return mr($,E,P),jr(p,A,m,d,$)}function Ar(p,A,m,d,E,P){var $=new Uint8Array(32);return mr($,E,P),Mi(p,A,m,d,$)}var Er=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591];function z(p,A,m,d){for(var E=new Int32Array(16),P=new Int32Array(16),$,J,ae,me,he,tt,ge,Te,Le,Fe,Me,Ue,Oe,De,Ae,be,pe,Ee,_e,de,Q,W,ie,j,Z,oe,Ce=p[0],He=p[1],We=p[2],Qe=p[3],S=p[4],Ke=p[5],nt=p[6],rt=p[7],qe=A[0],Je=A[1],Ze=A[2],Ct=A[3],ct=A[4],St=A[5],wt=A[6],It=A[7],Lt=0;d>=128;){for(_e=0;_e<16;_e++)de=8*_e+Lt,E[_e]=m[de+0]<<24|m[de+1]<<16|m[de+2]<<8|m[de+3],P[_e]=m[de+4]<<24|m[de+5]<<16|m[de+6]<<8|m[de+7];for(_e=0;_e<80;_e++)if($=Ce,J=He,ae=We,me=Qe,he=S,tt=Ke,ge=nt,Te=rt,Le=qe,Fe=Je,Me=Ze,Ue=Ct,Oe=ct,De=St,Ae=wt,be=It,Q=rt,W=It,ie=W&65535,j=W>>>16,Z=Q&65535,oe=Q>>>16,Q=(S>>>14|ct<<18)^(S>>>18|ct<<14)^(ct>>>9|S<<23),W=(ct>>>14|S<<18)^(ct>>>18|S<<14)^(S>>>9|ct<<23),ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,Q=S&Ke^~S&nt,W=ct&St^~ct&wt,ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,Q=Er[_e*2],W=Er[_e*2+1],ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,Q=E[_e%16],W=P[_e%16],ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,j+=ie>>>16,Z+=j>>>16,oe+=Z>>>16,pe=Z&65535|oe<<16,Ee=ie&65535|j<<16,Q=pe,W=Ee,ie=W&65535,j=W>>>16,Z=Q&65535,oe=Q>>>16,Q=(Ce>>>28|qe<<4)^(qe>>>2|Ce<<30)^(qe>>>7|Ce<<25),W=(qe>>>28|Ce<<4)^(Ce>>>2|qe<<30)^(Ce>>>7|qe<<25),ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,Q=Ce&He^Ce&We^He&We,W=qe&Je^qe&Ze^Je&Ze,ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,j+=ie>>>16,Z+=j>>>16,oe+=Z>>>16,Te=Z&65535|oe<<16,be=ie&65535|j<<16,Q=me,W=Ue,ie=W&65535,j=W>>>16,Z=Q&65535,oe=Q>>>16,Q=pe,W=Ee,ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,j+=ie>>>16,Z+=j>>>16,oe+=Z>>>16,me=Z&65535|oe<<16,Ue=ie&65535|j<<16,He=$,We=J,Qe=ae,S=me,Ke=he,nt=tt,rt=ge,Ce=Te,Je=Le,Ze=Fe,Ct=Me,ct=Ue,St=Oe,wt=De,It=Ae,qe=be,_e%16===15)for(de=0;de<16;de++)Q=E[de],W=P[de],ie=W&65535,j=W>>>16,Z=Q&65535,oe=Q>>>16,Q=E[(de+9)%16],W=P[(de+9)%16],ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,pe=E[(de+1)%16],Ee=P[(de+1)%16],Q=(pe>>>1|Ee<<31)^(pe>>>8|Ee<<24)^pe>>>7,W=(Ee>>>1|pe<<31)^(Ee>>>8|pe<<24)^(Ee>>>7|pe<<25),ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,pe=E[(de+14)%16],Ee=P[(de+14)%16],Q=(pe>>>19|Ee<<13)^(Ee>>>29|pe<<3)^pe>>>6,W=(Ee>>>19|pe<<13)^(pe>>>29|Ee<<3)^(Ee>>>6|pe<<26),ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,j+=ie>>>16,Z+=j>>>16,oe+=Z>>>16,E[de]=Z&65535|oe<<16,P[de]=ie&65535|j<<16;Q=Ce,W=qe,ie=W&65535,j=W>>>16,Z=Q&65535,oe=Q>>>16,Q=p[0],W=A[0],ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,j+=ie>>>16,Z+=j>>>16,oe+=Z>>>16,p[0]=Ce=Z&65535|oe<<16,A[0]=qe=ie&65535|j<<16,Q=He,W=Je,ie=W&65535,j=W>>>16,Z=Q&65535,oe=Q>>>16,Q=p[1],W=A[1],ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,j+=ie>>>16,Z+=j>>>16,oe+=Z>>>16,p[1]=He=Z&65535|oe<<16,A[1]=Je=ie&65535|j<<16,Q=We,W=Ze,ie=W&65535,j=W>>>16,Z=Q&65535,oe=Q>>>16,Q=p[2],W=A[2],ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,j+=ie>>>16,Z+=j>>>16,oe+=Z>>>16,p[2]=We=Z&65535|oe<<16,A[2]=Ze=ie&65535|j<<16,Q=Qe,W=Ct,ie=W&65535,j=W>>>16,Z=Q&65535,oe=Q>>>16,Q=p[3],W=A[3],ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,j+=ie>>>16,Z+=j>>>16,oe+=Z>>>16,p[3]=Qe=Z&65535|oe<<16,A[3]=Ct=ie&65535|j<<16,Q=S,W=ct,ie=W&65535,j=W>>>16,Z=Q&65535,oe=Q>>>16,Q=p[4],W=A[4],ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,j+=ie>>>16,Z+=j>>>16,oe+=Z>>>16,p[4]=S=Z&65535|oe<<16,A[4]=ct=ie&65535|j<<16,Q=Ke,W=St,ie=W&65535,j=W>>>16,Z=Q&65535,oe=Q>>>16,Q=p[5],W=A[5],ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,j+=ie>>>16,Z+=j>>>16,oe+=Z>>>16,p[5]=Ke=Z&65535|oe<<16,A[5]=St=ie&65535|j<<16,Q=nt,W=wt,ie=W&65535,j=W>>>16,Z=Q&65535,oe=Q>>>16,Q=p[6],W=A[6],ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,j+=ie>>>16,Z+=j>>>16,oe+=Z>>>16,p[6]=nt=Z&65535|oe<<16,A[6]=wt=ie&65535|j<<16,Q=rt,W=It,ie=W&65535,j=W>>>16,Z=Q&65535,oe=Q>>>16,Q=p[7],W=A[7],ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,j+=ie>>>16,Z+=j>>>16,oe+=Z>>>16,p[7]=rt=Z&65535|oe<<16,A[7]=It=ie&65535|j<<16,Lt+=128,d-=128}return d}function ue(p,A,m){var d=new Int32Array(8),E=new Int32Array(8),P=new Uint8Array(256),$,J=m;for(d[0]=1779033703,d[1]=3144134277,d[2]=1013904242,d[3]=2773480762,d[4]=1359893119,d[5]=2600822924,d[6]=528734635,d[7]=1541459225,E[0]=4089235720,E[1]=2227873595,E[2]=4271175723,E[3]=1595750129,E[4]=2917565137,E[5]=725511199,E[6]=4215389547,E[7]=327033209,z(d,E,A,m),m%=128,$=0;$<m;$++)P[$]=A[J-m+$];for(P[m]=128,m=256-128*(m<112?1:0),P[m-9]=0,g(P,m-8,J/536870912|0,J<<3),z(d,E,P,m),$=0;$<8;$++)g(p,8*$,d[$],E[$]);return 0}function xe(p,A){var m=t(),d=t(),E=t(),P=t(),$=t(),J=t(),ae=t(),me=t(),he=t();fe(m,p[1],p[0]),fe(he,A[1],A[0]),se(m,m,he),X(d,p[0],p[1]),X(he,A[0],A[1]),se(d,d,he),se(E,p[3],A[3]),se(E,E,f),se(P,p[2],A[2]),X(P,P,P),fe($,d,m),fe(J,P,E),X(ae,P,E),X(me,d,m),se(p[0],$,J),se(p[1],me,ae),se(p[2],ae,J),se(p[3],$,me)}function Pe(p,A,m){var d;for(d=0;d<4;d++)ce(p[d],A[d],m)}function je(p,A){var m=t(),d=t(),E=t();_t(E,A[2]),se(m,A[0],E),se(d,A[1],E),D(p,d),p[31]^=N(m)<<7}function Nt(p,A,m){var d,E;for(Y(p[0],i),Y(p[1],o),Y(p[2],o),Y(p[3],i),E=255;E>=0;--E)d=m[E/8|0]>>(E&7)&1,Pe(p,A,d),xe(A,p),xe(p,p),Pe(p,A,d)}function En(p,A){var m=[t(),t(),t(),t()];Y(m[0],l),Y(m[1],u),Y(m[2],o),se(m[3],l,u),Nt(p,m,A)}function tn(p,A,m){var d=new Uint8Array(64),E=[t(),t(),t(),t()],P;for(m||e(A,32),ue(d,A,32),d[0]&=248,d[31]&=127,d[31]|=64,En(E,d),je(p,E),P=0;P<32;P++)A[P+32]=p[P];return 0}var _r=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function ot(p,A){var m,d,E,P;for(d=63;d>=32;--d){for(m=0,E=d-32,P=d-12;E<P;++E)A[E]+=m-16*A[d]*_r[E-(d-32)],m=A[E]+128>>8,A[E]-=m*256;A[E]+=m,A[d]=0}for(m=0,E=0;E<32;E++)A[E]+=m-(A[31]>>4)*_r[E],m=A[E]>>8,A[E]&=255;for(E=0;E<32;E++)A[E]-=m*_r[E];for(d=0;d<32;d++)A[d+1]+=A[d]>>8,p[d]=A[d]&255}function Ut(p){var A=new Float64Array(64),m;for(m=0;m<64;m++)A[m]=p[m];for(m=0;m<64;m++)p[m]=0;ot(p,A)}function Tt(p,A,m,d){var E=new Uint8Array(64),P=new Uint8Array(64),$=new Uint8Array(64),J,ae,me=new Float64Array(64),he=[t(),t(),t(),t()];ue(E,d,32),E[0]&=248,E[31]&=127,E[31]|=64;var tt=m+64;for(J=0;J<m;J++)p[64+J]=A[J];for(J=0;J<32;J++)p[32+J]=E[32+J];for(ue($,p.subarray(32),m+32),Ut($),En(he,$),je(p,he),J=32;J<64;J++)p[J]=d[J];for(ue(P,p,m+64),Ut(P),J=0;J<64;J++)me[J]=0;for(J=0;J<32;J++)me[J]=$[J];for(J=0;J<32;J++)for(ae=0;ae<32;ae++)me[J+ae]+=P[J]*E[ae];return ot(p.subarray(32),me),tt}function bt(p,A){var m=t(),d=t(),E=t(),P=t(),$=t(),J=t(),ae=t();return Y(p[2],o),H(p[1],A),ze(E,p[1]),se(P,E,c),fe(E,E,p[2]),X(P,p[2],P),ze($,P),ze(J,$),se(ae,J,$),se(m,ae,E),se(m,m,P),An(m,m),se(m,m,E),se(m,m,P),se(m,m,P),se(p[0],m,P),ze(d,p[0]),se(d,d,P),v(d,E)&&se(p[0],p[0],h),ze(d,p[0]),se(d,d,P),v(d,E)?-1:(N(p[0])===A[31]>>7&&fe(p[0],i,p[0]),se(p[3],p[0],p[1]),0)}function ut(p,A,m,d){var E,P,$=new Uint8Array(32),J=new Uint8Array(64),ae=[t(),t(),t(),t()],me=[t(),t(),t(),t()];if(P=-1,m<64||bt(me,d))return-1;for(E=0;E<m;E++)p[E]=A[E];for(E=0;E<32;E++)p[E+32]=d[E];if(ue(J,p,m),Ut(J),Nt(ae,me,J),En(me,A.subarray(32)),xe(ae,me),je($,ae),m-=64,b(A,0,$,0)){for(E=0;E<m;E++)p[E]=0;return-1}for(E=0;E<m;E++)p[E]=A[E+64];return P=m,P}var an=32,xt=24,tr=32,yr=16,Jr=32,$i=32,Zr=32,ei=32,Zs=32,mc=xt,Mh=tr,$h=yr,Bn=64,nr=32,br=64,eo=32,to=64;n.lowlevel={crypto_core_hsalsa20:k,crypto_stream_xor:w,crypto_stream:x,crypto_stream_salsa20_xor:ee,crypto_stream_salsa20:O,crypto_onetimeauth:U,crypto_onetimeauth_verify:R,crypto_verify_16:_,crypto_verify_32:b,crypto_secretbox:re,crypto_secretbox_open:G,crypto_scalarmult:pr,crypto_scalarmult_base:gr,crypto_box_beforenm:mr,crypto_box_afternm:jr,crypto_box:Xr,crypto_box_open:Ar,crypto_box_keypair:kn,crypto_hash:ue,crypto_sign:Tt,crypto_sign_keypair:tn,crypto_sign_open:ut,crypto_secretbox_KEYBYTES:an,crypto_secretbox_NONCEBYTES:xt,crypto_secretbox_ZEROBYTES:tr,crypto_secretbox_BOXZEROBYTES:yr,crypto_scalarmult_BYTES:Jr,crypto_scalarmult_SCALARBYTES:$i,crypto_box_PUBLICKEYBYTES:Zr,crypto_box_SECRETKEYBYTES:ei,crypto_box_BEFORENMBYTES:Zs,crypto_box_NONCEBYTES:mc,crypto_box_ZEROBYTES:Mh,crypto_box_BOXZEROBYTES:$h,crypto_sign_BYTES:Bn,crypto_sign_PUBLICKEYBYTES:nr,crypto_sign_SECRETKEYBYTES:br,crypto_sign_SEEDBYTES:eo,crypto_hash_BYTES:to};function Ac(p,A){if(p.length!==an)throw new Error("bad key size");if(A.length!==xt)throw new Error("bad nonce size")}function Fh(p,A){if(p.length!==Zr)throw new Error("bad public key size");if(A.length!==ei)throw new Error("bad secret key size")}function nn(){var p,A;for(A=0;A<arguments.length;A++)if((p=Object.prototype.toString.call(arguments[A]))!=="[object Uint8Array]")throw new TypeError("unexpected type "+p+", use Uint8Array")}function Ec(p){for(var A=0;A<p.length;A++)p[A]=0}n.util||(n.util={},n.util.decodeUTF8=n.util.encodeUTF8=n.util.encodeBase64=n.util.decodeBase64=function(){throw new Error("nacl.util moved into separate package: https://github.com/dchest/tweetnacl-util-js")}),n.randomBytes=function(p){var A=new Uint8Array(p);return e(A,p),A},n.secretbox=function(p,A,m){nn(p,A,m),Ac(m,A);for(var d=new Uint8Array(tr+p.length),E=new Uint8Array(d.length),P=0;P<p.length;P++)d[P+tr]=p[P];return re(E,d,d.length,A,m),E.subarray(yr)},n.secretbox.open=function(p,A,m){nn(p,A,m),Ac(m,A);for(var d=new Uint8Array(yr+p.length),E=new Uint8Array(d.length),P=0;P<p.length;P++)d[P+yr]=p[P];return d.length<32||G(E,d,d.length,A,m)!==0?!1:E.subarray(tr)},n.secretbox.keyLength=an,n.secretbox.nonceLength=xt,n.secretbox.overheadLength=yr,n.scalarMult=function(p,A){if(nn(p,A),p.length!==$i)throw new Error("bad n size");if(A.length!==Jr)throw new Error("bad p size");var m=new Uint8Array(Jr);return pr(m,p,A),m},n.scalarMult.base=function(p){if(nn(p),p.length!==$i)throw new Error("bad n size");var A=new Uint8Array(Jr);return gr(A,p),A},n.scalarMult.scalarLength=$i,n.scalarMult.groupElementLength=Jr,n.box=function(p,A,m,d){var E=n.box.before(m,d);return n.secretbox(p,A,E)},n.box.before=function(p,A){nn(p,A),Fh(p,A);var m=new Uint8Array(Zs);return mr(m,p,A),m},n.box.after=n.secretbox,n.box.open=function(p,A,m,d){var E=n.box.before(m,d);return n.secretbox.open(p,A,E)},n.box.open.after=n.secretbox.open,n.box.keyPair=function(){var p=new Uint8Array(Zr),A=new Uint8Array(ei);return kn(p,A),{publicKey:p,secretKey:A}},n.box.keyPair.fromSecretKey=function(p){if(nn(p),p.length!==ei)throw new Error("bad secret key size");var A=new Uint8Array(Zr);return gr(A,p),{publicKey:A,secretKey:new Uint8Array(p)}},n.box.publicKeyLength=Zr,n.box.secretKeyLength=ei,n.box.sharedKeyLength=Zs,n.box.nonceLength=mc,n.box.overheadLength=n.secretbox.overheadLength,n.sign=function(p,A){if(nn(p,A),A.length!==br)throw new Error("bad secret key size");var m=new Uint8Array(Bn+p.length);return Tt(m,p,p.length,A),m},n.sign.open=function(p,A){if(arguments.length!==2)throw new Error("nacl.sign.open accepts 2 arguments; did you mean to use nacl.sign.detached.verify?");if(nn(p,A),A.length!==nr)throw new Error("bad public key size");var m=new Uint8Array(p.length),d=ut(m,p,p.length,A);if(d<0)return null;for(var E=new Uint8Array(d),P=0;P<E.length;P++)E[P]=m[P];return E},n.sign.detached=function(p,A){for(var m=n.sign(p,A),d=new Uint8Array(Bn),E=0;E<d.length;E++)d[E]=m[E];return d},n.sign.detached.verify=function(p,A,m){if(nn(p,A,m),A.length!==Bn)throw new Error("bad signature size");if(m.length!==nr)throw new Error("bad public key size");var d=new Uint8Array(Bn+p.length),E=new Uint8Array(Bn+p.length),P;for(P=0;P<Bn;P++)d[P]=A[P];for(P=0;P<p.length;P++)d[P+Bn]=p[P];return ut(E,d,d.length,m)>=0},n.sign.keyPair=function(){var p=new Uint8Array(nr),A=new Uint8Array(br);return tn(p,A),{publicKey:p,secretKey:A}},n.sign.keyPair.fromSecretKey=function(p){if(nn(p),p.length!==br)throw new Error("bad secret key size");for(var A=new Uint8Array(nr),m=0;m<A.length;m++)A[m]=p[32+m];return{publicKey:A,secretKey:new Uint8Array(p)}},n.sign.keyPair.fromSeed=function(p){if(nn(p),p.length!==eo)throw new Error("bad seed size");for(var A=new Uint8Array(nr),m=new Uint8Array(br),d=0;d<32;d++)m[d]=p[d];return tn(A,m,!0),{publicKey:A,secretKey:m}},n.sign.publicKeyLength=nr,n.sign.secretKeyLength=br,n.sign.seedLength=eo,n.sign.signatureLength=Bn,n.hash=function(p){nn(p);var A=new Uint8Array(to);return ue(A,p,p.length),A},n.hash.hashLength=to,n.verify=function(p,A){return nn(p,A),p.length===0||A.length===0||p.length!==A.length?!1:y(p,0,A,0,p.length)===0},n.setPRNG=function(p){e=p},(function(){var p=typeof self<"u"?self.crypto||self.msCrypto:null;if(p&&p.getRandomValues){var A=65536;n.setPRNG(function(m,d){var E,P=new Uint8Array(d);for(E=0;E<d;E+=A)p.getRandomValues(P.subarray(E,E+Math.min(d-E,A)));for(E=0;E<d;E++)m[E]=P[E];Ec(P)})}else typeof require<"u"&&(p=require("crypto"),p&&p.randomBytes&&n.setPRNG(function(m,d){var E,P=p.randomBytes(d);for(E=0;E<d;E++)m[E]=P[E];Ec(P)}))})()})(typeof us<"u"&&us.exports?us.exports:self.nacl=self.nacl||{})});var No=at((Lx,pu)=>{"use strict";var ko=hu().lowlevel.crypto_hash,Pn=0,fr=function(){this.S=[new Uint32Array([3509652390,2564797868,805139163,3491422135,3101798381,1780907670,3128725573,4046225305,614570311,3012652279,134345442,2240740374,1667834072,1901547113,2757295779,4103290238,227898511,1921955416,1904987480,2182433518,2069144605,3260701109,2620446009,720527379,3318853667,677414384,3393288472,3101374703,2390351024,1614419982,1822297739,2954791486,3608508353,3174124327,2024746970,1432378464,3864339955,2857741204,1464375394,1676153920,1439316330,715854006,3033291828,289532110,2706671279,2087905683,3018724369,1668267050,732546397,1947742710,3462151702,2609353502,2950085171,1814351708,2050118529,680887927,999245976,1800124847,3300911131,1713906067,1641548236,4213287313,1216130144,1575780402,4018429277,3917837745,3693486850,3949271944,596196993,3549867205,258830323,2213823033,772490370,2760122372,1774776394,2652871518,566650946,4142492826,1728879713,2882767088,1783734482,3629395816,2517608232,2874225571,1861159788,326777828,3124490320,2130389656,2716951837,967770486,1724537150,2185432712,2364442137,1164943284,2105845187,998989502,3765401048,2244026483,1075463327,1455516326,1322494562,910128902,469688178,1117454909,936433444,3490320968,3675253459,1240580251,122909385,2157517691,634681816,4142456567,3825094682,3061402683,2540495037,79693498,3249098678,1084186820,1583128258,426386531,1761308591,1047286709,322548459,995290223,1845252383,2603652396,3431023940,2942221577,3202600964,3727903485,1712269319,422464435,3234572375,1170764815,3523960633,3117677531,1434042557,442511882,3600875718,1076654713,1738483198,4213154764,2393238008,3677496056,1014306527,4251020053,793779912,2902807211,842905082,4246964064,1395751752,1040244610,2656851899,3396308128,445077038,3742853595,3577915638,679411651,2892444358,2354009459,1767581616,3150600392,3791627101,3102740896,284835224,4246832056,1258075500,768725851,2589189241,3069724005,3532540348,1274779536,3789419226,2764799539,1660621633,3471099624,4011903706,913787905,3497959166,737222580,2514213453,2928710040,3937242737,1804850592,3499020752,2949064160,2386320175,2390070455,2415321851,4061277028,2290661394,2416832540,1336762016,1754252060,3520065937,3014181293,791618072,3188594551,3933548030,2332172193,3852520463,3043980520,413987798,3465142937,3030929376,4245938359,2093235073,3534596313,375366246,2157278981,2479649556,555357303,3870105701,2008414854,3344188149,4221384143,3956125452,2067696032,3594591187,2921233993,2428461,544322398,577241275,1471733935,610547355,4027169054,1432588573,1507829418,2025931657,3646575487,545086370,48609733,2200306550,1653985193,298326376,1316178497,3007786442,2064951626,458293330,2589141269,3591329599,3164325604,727753846,2179363840,146436021,1461446943,4069977195,705550613,3059967265,3887724982,4281599278,3313849956,1404054877,2845806497,146425753,1854211946]),new Uint32Array([1266315497,3048417604,3681880366,3289982499,290971e4,1235738493,2632868024,2414719590,3970600049,1771706367,1449415276,3266420449,422970021,1963543593,2690192192,3826793022,1062508698,1531092325,1804592342,2583117782,2714934279,4024971509,1294809318,4028980673,1289560198,2221992742,1669523910,35572830,157838143,1052438473,1016535060,1802137761,1753167236,1386275462,3080475397,2857371447,1040679964,2145300060,2390574316,1461121720,2956646967,4031777805,4028374788,33600511,2920084762,1018524850,629373528,3691585981,3515945977,2091462646,2486323059,586499841,988145025,935516892,3367335476,2599673255,2839830854,265290510,3972581182,2759138881,3795373465,1005194799,847297441,406762289,1314163512,1332590856,1866599683,4127851711,750260880,613907577,1450815602,3165620655,3734664991,3650291728,3012275730,3704569646,1427272223,778793252,1343938022,2676280711,2052605720,1946737175,3164576444,3914038668,3967478842,3682934266,1661551462,3294938066,4011595847,840292616,3712170807,616741398,312560963,711312465,1351876610,322626781,1910503582,271666773,2175563734,1594956187,70604529,3617834859,1007753275,1495573769,4069517037,2549218298,2663038764,504708206,2263041392,3941167025,2249088522,1514023603,1998579484,1312622330,694541497,2582060303,2151582166,1382467621,776784248,2618340202,3323268794,2497899128,2784771155,503983604,4076293799,907881277,423175695,432175456,1378068232,4145222326,3954048622,3938656102,3820766613,2793130115,2977904593,26017576,3274890735,3194772133,1700274565,1756076034,4006520079,3677328699,720338349,1533947780,354530856,688349552,3973924725,1637815568,332179504,3949051286,53804574,2852348879,3044236432,1282449977,3583942155,3416972820,4006381244,1617046695,2628476075,3002303598,1686838959,431878346,2686675385,1700445008,1080580658,1009431731,832498133,3223435511,2605976345,2271191193,2516031870,1648197032,4164389018,2548247927,300782431,375919233,238389289,3353747414,2531188641,2019080857,1475708069,455242339,2609103871,448939670,3451063019,1395535956,2413381860,1841049896,1491858159,885456874,4264095073,4001119347,1565136089,3898914787,1108368660,540939232,1173283510,2745871338,3681308437,4207628240,3343053890,4016749493,1699691293,1103962373,3625875870,2256883143,3830138730,1031889488,3479347698,1535977030,4236805024,3251091107,2132092099,1774941330,1199868427,1452454533,157007616,2904115357,342012276,595725824,1480756522,206960106,497939518,591360097,863170706,2375253569,3596610801,1814182875,2094937945,3421402208,1082520231,3463918190,2785509508,435703966,3908032597,1641649973,2842273706,3305899714,1510255612,2148256476,2655287854,3276092548,4258621189,236887753,3681803219,274041037,1734335097,3815195456,3317970021,1899903192,1026095262,4050517792,356393447,2410691914,3873677099,3682840055]),new Uint32Array([3913112168,2491498743,4132185628,2489919796,1091903735,1979897079,3170134830,3567386728,3557303409,857797738,1136121015,1342202287,507115054,2535736646,337727348,3213592640,1301675037,2528481711,1895095763,1721773893,3216771564,62756741,2142006736,835421444,2531993523,1442658625,3659876326,2882144922,676362277,1392781812,170690266,3921047035,1759253602,3611846912,1745797284,664899054,1329594018,3901205900,3045908486,2062866102,2865634940,3543621612,3464012697,1080764994,553557557,3656615353,3996768171,991055499,499776247,1265440854,648242737,3940784050,980351604,3713745714,1749149687,3396870395,4211799374,3640570775,1161844396,3125318951,1431517754,545492359,4268468663,3499529547,1437099964,2702547544,3433638243,2581715763,2787789398,1060185593,1593081372,2418618748,4260947970,69676912,2159744348,86519011,2512459080,3838209314,1220612927,3339683548,133810670,1090789135,1078426020,1569222167,845107691,3583754449,4072456591,1091646820,628848692,1613405280,3757631651,526609435,236106946,48312990,2942717905,3402727701,1797494240,859738849,992217954,4005476642,2243076622,3870952857,3732016268,765654824,3490871365,2511836413,1685915746,3888969200,1414112111,2273134842,3281911079,4080962846,172450625,2569994100,980381355,4109958455,2819808352,2716589560,2568741196,3681446669,3329971472,1835478071,660984891,3704678404,4045999559,3422617507,3040415634,1762651403,1719377915,3470491036,2693910283,3642056355,3138596744,1364962596,2073328063,1983633131,926494387,3423689081,2150032023,4096667949,1749200295,3328846651,309677260,2016342300,1779581495,3079819751,111262694,1274766160,443224088,298511866,1025883608,3806446537,1145181785,168956806,3641502830,3584813610,1689216846,3666258015,3200248200,1692713982,2646376535,4042768518,1618508792,1610833997,3523052358,4130873264,2001055236,3610705100,2202168115,4028541809,2961195399,1006657119,2006996926,3186142756,1430667929,3210227297,1314452623,4074634658,4101304120,2273951170,1399257539,3367210612,3027628629,1190975929,2062231137,2333990788,2221543033,2438960610,1181637006,548689776,2362791313,3372408396,3104550113,3145860560,296247880,1970579870,3078560182,3769228297,1714227617,3291629107,3898220290,166772364,1251581989,493813264,448347421,195405023,2709975567,677966185,3703036547,1463355134,2715995803,1338867538,1343315457,2802222074,2684532164,233230375,2599980071,2000651841,3277868038,1638401717,4028070440,3237316320,6314154,819756386,300326615,590932579,1405279636,3267499572,3150704214,2428286686,3959192993,3461946742,1862657033,1266418056,963775037,2089974820,2263052895,1917689273,448879540,3550394620,3981727096,150775221,3627908307,1303187396,508620638,2975983352,2726630617,1817252668,1876281319,1457606340,908771278,3720792119,3617206836,2455994898,1729034894,1080033504]),new Uint32Array([976866871,3556439503,2881648439,1522871579,1555064734,1336096578,3548522304,2579274686,3574697629,3205460757,3593280638,3338716283,3079412587,564236357,2993598910,1781952180,1464380207,3163844217,3332601554,1699332808,1393555694,1183702653,3581086237,1288719814,691649499,2847557200,2895455976,3193889540,2717570544,1781354906,1676643554,2592534050,3230253752,1126444790,2770207658,2633158820,2210423226,2615765581,2414155088,3127139286,673620729,2805611233,1269405062,4015350505,3341807571,4149409754,1057255273,2012875353,2162469141,2276492801,2601117357,993977747,3918593370,2654263191,753973209,36408145,2530585658,25011837,3520020182,2088578344,530523599,2918365339,1524020338,1518925132,3760827505,3759777254,1202760957,3985898139,3906192525,674977740,4174734889,2031300136,2019492241,3983892565,4153806404,3822280332,352677332,2297720250,60907813,90501309,3286998549,1016092578,2535922412,2839152426,457141659,509813237,4120667899,652014361,1966332200,2975202805,55981186,2327461051,676427537,3255491064,2882294119,3433927263,1307055953,942726286,933058658,2468411793,3933900994,4215176142,1361170020,2001714738,2830558078,3274259782,1222529897,1679025792,2729314320,3714953764,1770335741,151462246,3013232138,1682292957,1483529935,471910574,1539241949,458788160,3436315007,1807016891,3718408830,978976581,1043663428,3165965781,1927990952,4200891579,2372276910,3208408903,3533431907,1412390302,2931980059,4132332400,1947078029,3881505623,4168226417,2941484381,1077988104,1320477388,886195818,18198404,3786409e3,2509781533,112762804,3463356488,1866414978,891333506,18488651,661792760,1628790961,3885187036,3141171499,876946877,2693282273,1372485963,791857591,2686433993,3759982718,3167212022,3472953795,2716379847,445679433,3561995674,3504004811,3574258232,54117162,3331405415,2381918588,3769707343,4154350007,1140177722,4074052095,668550556,3214352940,367459370,261225585,2610173221,4209349473,3468074219,3265815641,314222801,3066103646,3808782860,282218597,3406013506,3773591054,379116347,1285071038,846784868,2669647154,3771962079,3550491691,2305946142,453669953,1268987020,3317592352,3279303384,3744833421,2610507566,3859509063,266596637,3847019092,517658769,3462560207,3443424879,370717030,4247526661,2224018117,4143653529,4112773975,2788324899,2477274417,1456262402,2901442914,1517677493,1846949527,2295493580,3734397586,2176403920,1280348187,1908823572,3871786941,846861322,1172426758,3287448474,3383383037,1655181056,3139813346,901632758,1897031941,2986607138,3066810236,3447102507,1393639104,373351379,950779232,625454576,3124240540,4148612726,2007998917,544563296,2244738638,2330496472,2058025392,1291430526,424198748,50039436,29584100,3605783033,2429876329,2791104160,1057563949,3255363231,3075367218,3463963227,1469046755,985887462])],this.P=new Uint32Array([608135816,2242054355,320440878,57701188,2752067618,698298832,137296536,3964562569,1160258022,953160567,3193202383,887688300,3232508343,3380367581,1065670069,3041331479,2450970073,2306472731])};function hs(n,t,e){return(n[0][t[e+3]]+n[1][t[e+2]]^n[2][t[e+1]])+n[3][t[e]]}fr.prototype.encipher=function(n,t){t===void 0&&(t=new Uint8Array(n.buffer),n.byteOffset!==0&&(t=t.subarray(n.byteOffset))),n[0]^=this.P[0];for(var e=1;e<16;e+=2)n[1]^=hs(this.S,t,0)^this.P[e],n[0]^=hs(this.S,t,4)^this.P[e+1];var r=n[0];n[0]=n[1]^this.P[17],n[1]=r};fr.prototype.decipher=function(n){var t=new Uint8Array(n.buffer);n.byteOffset!==0&&(t=t.subarray(n.byteOffset)),n[0]^=this.P[17];for(var e=16;e>0;e-=2)n[1]^=hs(this.S,t,0)^this.P[e],n[0]^=hs(this.S,t,4)^this.P[e-1];var r=n[0];n[0]=n[1]^this.P[0],n[1]=r};function cr(n,t){var e,r=0;for(e=0;e<4;e++,Pn++)Pn>=t&&(Pn=0),r=r<<8|n[Pn];return r}fr.prototype.expand0state=function(n,t){var e=new Uint32Array(2),r,s,i=new Uint8Array(e.buffer);for(r=0,Pn=0;r<18;r++)this.P[r]^=cr(n,t);for(Pn=0,r=0;r<18;r+=2)this.encipher(e,i),this.P[r]=e[0],this.P[r+1]=e[1];for(r=0;r<4;r++)for(s=0;s<256;s+=2)this.encipher(e,i),this.S[r][s]=e[0],this.S[r][s+1]=e[1]};fr.prototype.expandstate=function(n,t,e,r){var s=new Uint32Array(2),i,o;for(i=0,Pn=0;i<18;i++)this.P[i]^=cr(e,r);for(i=0,Pn=0;i<18;i+=2)s[0]^=cr(n,t),s[1]^=cr(n,t),this.encipher(s),this.P[i]=s[0],this.P[i+1]=s[1];for(i=0;i<4;i++)for(o=0;o<256;o+=2)s[0]^=cr(n,t),s[1]^=cr(n,t),this.encipher(s),this.S[i][o]=s[0],this.S[i][o+1]=s[1];Pn=0};fr.prototype.enc=function(n,t){for(var e=0;e<t;e++)this.encipher(n.subarray(e*2))};fr.prototype.dec=function(n,t){for(var e=0;e<t;e++)this.decipher(n.subarray(e*2))};var ds=8,Bo=32;function Ro(n,t,e){var r=new fr,s=new Uint32Array(ds),i,o=new Uint8Array([79,120,121,99,104,114,111,109,97,116,105,99,66,108,111,119,102,105,115,104,83,119,97,116,68,121,110,97,109,105,116,101]);for(r.expandstate(t,64,n,64),i=0;i<64;i++)r.expand0state(t,64),r.expand0state(n,64);for(i=0;i<ds;i++)s[i]=cr(o,o.byteLength);for(i=0;i<64;i++)r.enc(s,s.byteLength/8);for(i=0;i<ds;i++)e[4*i+3]=s[i]>>>24,e[4*i+2]=s[i]>>>16,e[4*i+1]=s[i]>>>8,e[4*i+0]=s[i]}function hg(n,t,e,r,s,i,o){var a=new Uint8Array(64),c=new Uint8Array(64),f=new Uint8Array(Bo),l=new Uint8Array(Bo),u=new Uint8Array(r+4),h,g,y,_,b,C,L=i;if(o<1||t===0||r===0||i===0||i>f.byteLength*f.byteLength||r>1<<20)return-1;for(_=Math.floor((i+f.byteLength-1)/f.byteLength),y=Math.floor((i+_-1)/_),h=0;h<r;h++)u[h]=e[h];for(ko(a,n,t),C=1;i>0;C++){for(u[r+0]=C>>>24,u[r+1]=C>>>16,u[r+2]=C>>>8,u[r+3]=C,ko(c,u,r+4),Ro(a,c,l),h=f.byteLength;h--;)f[h]=l[h];for(h=1;h<o;h++)for(ko(c,l,l.byteLength),Ro(a,c,l),g=0;g<f.byteLength;g++)f[g]^=l[g];for(y=Math.min(y,i),h=0;h<y&&(b=h*_+(C-1),!(b>=L));h++)s[b]=f[h];i-=h}return 0}pu.exports={BLOCKS:ds,HASHSIZE:Bo,hash:Ro,pbkdf:hg}});var Ln=at((Ux,gs)=>{"use strict";var Tn=require("crypto"),Lr;try{Lr=require("cpu-features")()}catch{}var{bindingAvailable:gu,CIPHER_INFO:pg,MAC_INFO:gg}=Kn(),mu=(()=>{if(typeof Tn.sign=="function"&&typeof Tn.verify=="function"){let n=`-----BEGIN PRIVATE KEY-----\r
|
|
1
|
+
"use strict";var Hh=Object.create;var yc=Object.defineProperty;var Qh=Object.getOwnPropertyDescriptor;var Wh=Object.getOwnPropertyNames;var qh=Object.getPrototypeOf,Kh=Object.prototype.hasOwnProperty;var at=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports);var Vh=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Wh(t))!Kh.call(n,s)&&s!==e&&yc(n,s,{get:()=>t[s],enumerable:!(r=Qh(t,s))||r.enumerable});return n};var Vt=(n,t,e)=>(e=n!=null?Hh(qh(n)):{},Vh(t||!n||!n.__esModule?yc(e,"default",{value:n,enumerable:!0}):e,n));var Fi=at((tE,bc)=>{bc.exports={newInvalidAsn1Error:function(n){var t=new Error;return t.name="InvalidAsn1Error",t.message=n||"",t}}});var Hi=at((nE,xc)=>{xc.exports={EOC:0,Boolean:1,Integer:2,BitString:3,OctetString:4,Null:5,OID:6,ObjectDescriptor:7,External:8,Real:9,Enumeration:10,PDV:11,Utf8String:12,RelativeOID:13,Sequence:16,Set:17,NumericString:18,PrintableString:19,T61String:20,VideotexString:21,IA5String:22,UTCTime:23,GeneralizedTime:24,GraphicString:25,VisibleString:26,GeneralString:28,UniversalString:29,CharacterString:30,BMPString:31,Constructor:32,Context:128}});var no=at((rE,Sc)=>{"use strict";var Qi=require("buffer"),xr=Qi.Buffer,cn={},fn;for(fn in Qi)Qi.hasOwnProperty(fn)&&(fn==="SlowBuffer"||fn==="Buffer"||(cn[fn]=Qi[fn]));var Sr=cn.Buffer={};for(fn in xr)xr.hasOwnProperty(fn)&&(fn==="allocUnsafe"||fn==="allocUnsafeSlow"||(Sr[fn]=xr[fn]));cn.Buffer.prototype=xr.prototype;(!Sr.from||Sr.from===Uint8Array.from)&&(Sr.from=function(n,t,e){if(typeof n=="number")throw new TypeError('The "value" argument must not be of type number. Received type '+typeof n);if(n&&typeof n.length>"u")throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof n);return xr(n,t,e)});Sr.alloc||(Sr.alloc=function(n,t,e){if(typeof n!="number")throw new TypeError('The "size" argument must be of type number. Received type '+typeof n);if(n<0||n>=2*(1<<30))throw new RangeError('The value "'+n+'" is invalid for option "size"');var r=xr(n);return!t||t.length===0?r.fill(0):typeof e=="string"?r.fill(t,e):r.fill(t),r});if(!cn.kStringMaxLength)try{cn.kStringMaxLength=process.binding("buffer").kStringMaxLength}catch{}cn.constants||(cn.constants={MAX_LENGTH:cn.kMaxLength},cn.kStringMaxLength&&(cn.constants.MAX_STRING_LENGTH=cn.kStringMaxLength));Sc.exports=cn});var Cc=at((iE,Ic)=>{var Gh=require("assert"),wc=no().Buffer,ti=Hi(),Yh=Fi(),wr=Yh.newInvalidAsn1Error;function Gt(n){if(!n||!wc.isBuffer(n))throw new TypeError("data must be a node Buffer");this._buf=n,this._size=n.length,this._len=0,this._offset=0}Object.defineProperty(Gt.prototype,"length",{enumerable:!0,get:function(){return this._len}});Object.defineProperty(Gt.prototype,"offset",{enumerable:!0,get:function(){return this._offset}});Object.defineProperty(Gt.prototype,"remain",{get:function(){return this._size-this._offset}});Object.defineProperty(Gt.prototype,"buffer",{get:function(){return this._buf.slice(this._offset)}});Gt.prototype.readByte=function(n){if(this._size-this._offset<1)return null;var t=this._buf[this._offset]&255;return n||(this._offset+=1),t};Gt.prototype.peek=function(){return this.readByte(!0)};Gt.prototype.readLength=function(n){if(n===void 0&&(n=this._offset),n>=this._size)return null;var t=this._buf[n++]&255;if(t===null)return null;if((t&128)===128){if(t&=127,t===0)throw wr("Indefinite length not supported");if(t>4)throw wr("encoding too long");if(this._size-n<t)return null;this._len=0;for(var e=0;e<t;e++)this._len=(this._len<<8)+(this._buf[n++]&255)}else this._len=t;return n};Gt.prototype.readSequence=function(n){var t=this.peek();if(t===null)return null;if(n!==void 0&&n!==t)throw wr("Expected 0x"+n.toString(16)+": got 0x"+t.toString(16));var e=this.readLength(this._offset+1);return e===null?null:(this._offset=e,t)};Gt.prototype.readInt=function(){return this._readTag(ti.Integer)};Gt.prototype.readBoolean=function(){return this._readTag(ti.Boolean)!==0};Gt.prototype.readEnumeration=function(){return this._readTag(ti.Enumeration)};Gt.prototype.readString=function(n,t){n||(n=ti.OctetString);var e=this.peek();if(e===null)return null;if(e!==n)throw wr("Expected 0x"+n.toString(16)+": got 0x"+e.toString(16));var r=this.readLength(this._offset+1);if(r===null||this.length>this._size-r)return null;if(this._offset=r,this.length===0)return t?wc.alloc(0):"";var s=this._buf.slice(this._offset,this._offset+this.length);return this._offset+=this.length,t?s:s.toString("utf8")};Gt.prototype.readOID=function(n){n||(n=ti.OID);var t=this.readString(n,!0);if(t===null)return null;for(var e=[],r=0,s=0;s<t.length;s++){var i=t[s]&255;r<<=7,r+=i&127,(i&128)===0&&(e.push(r),r=0)}return r=e.shift(),e.unshift(r%40),e.unshift(r/40>>0),e.join(".")};Gt.prototype._readTag=function(n){Gh.ok(n!==void 0);var t=this.peek();if(t===null)return null;if(t!==n)throw wr("Expected 0x"+n.toString(16)+": got 0x"+t.toString(16));var e=this.readLength(this._offset+1);if(e===null)return null;if(this.length>4)throw wr("Integer too long: "+this.length);if(this.length>this._size-e)return null;this._offset=e;for(var r=this._buf[this._offset],s=0,i=0;i<this.length;i++)s<<=8,s|=this._buf[this._offset++]&255;return(r&128)===128&&i!==4&&(s-=1<<i*8),s>>0};Ic.exports=Gt});var kc=at((sE,vc)=>{var $n=require("assert"),Wi=no().Buffer,Fn=Hi(),zh=Fi(),qi=zh.newInvalidAsn1Error,jh={size:1024,growthFactor:8};function Xh(n,t){$n.ok(n),$n.equal(typeof n,"object"),$n.ok(t),$n.equal(typeof t,"object");var e=Object.getOwnPropertyNames(n);return e.forEach(function(r){if(!t[r]){var s=Object.getOwnPropertyDescriptor(n,r);Object.defineProperty(t,r,s)}}),t}function qt(n){n=Xh(jh,n||{}),this._buf=Wi.alloc(n.size||1024),this._size=this._buf.length,this._offset=0,this._options=n,this._seq=[]}Object.defineProperty(qt.prototype,"buffer",{get:function(){if(this._seq.length)throw qi(this._seq.length+" unended sequence(s)");return this._buf.slice(0,this._offset)}});qt.prototype.writeByte=function(n){if(typeof n!="number")throw new TypeError("argument must be a Number");this._ensure(1),this._buf[this._offset++]=n};qt.prototype.writeInt=function(n,t){if(typeof n!="number")throw new TypeError("argument must be a Number");typeof t!="number"&&(t=Fn.Integer);for(var e=4;((n&4286578688)===0||(n&4286578688)===-8388608)&&e>1;)e--,n<<=8;if(e>4)throw qi("BER ints cannot be > 0xffffffff");for(this._ensure(2+e),this._buf[this._offset++]=t,this._buf[this._offset++]=e;e-- >0;)this._buf[this._offset++]=(n&4278190080)>>>24,n<<=8};qt.prototype.writeNull=function(){this.writeByte(Fn.Null),this.writeByte(0)};qt.prototype.writeEnumeration=function(n,t){if(typeof n!="number")throw new TypeError("argument must be a Number");return typeof t!="number"&&(t=Fn.Enumeration),this.writeInt(n,t)};qt.prototype.writeBoolean=function(n,t){if(typeof n!="boolean")throw new TypeError("argument must be a Boolean");typeof t!="number"&&(t=Fn.Boolean),this._ensure(3),this._buf[this._offset++]=t,this._buf[this._offset++]=1,this._buf[this._offset++]=n?255:0};qt.prototype.writeString=function(n,t){if(typeof n!="string")throw new TypeError("argument must be a string (was: "+typeof n+")");typeof t!="number"&&(t=Fn.OctetString);var e=Wi.byteLength(n);this.writeByte(t),this.writeLength(e),e&&(this._ensure(e),this._buf.write(n,this._offset),this._offset+=e)};qt.prototype.writeBuffer=function(n,t){if(typeof t!="number")throw new TypeError("tag must be a number");if(!Wi.isBuffer(n))throw new TypeError("argument must be a buffer");this.writeByte(t),this.writeLength(n.length),this._ensure(n.length),n.copy(this._buf,this._offset,0,n.length),this._offset+=n.length};qt.prototype.writeStringArray=function(n){if(!n instanceof Array)throw new TypeError("argument must be an Array[String]");var t=this;n.forEach(function(e){t.writeString(e)})};qt.prototype.writeOID=function(n,t){if(typeof n!="string")throw new TypeError("argument must be a string");if(typeof t!="number"&&(t=Fn.OID),!/^([0-9]+\.){3,}[0-9]+$/.test(n))throw new Error("argument is not a valid OID string");function e(o,a){a<128?o.push(a):a<16384?(o.push(a>>>7|128),o.push(a&127)):a<2097152?(o.push(a>>>14|128),o.push((a>>>7|128)&255),o.push(a&127)):a<268435456?(o.push(a>>>21|128),o.push((a>>>14|128)&255),o.push((a>>>7|128)&255),o.push(a&127)):(o.push((a>>>28|128)&255),o.push((a>>>21|128)&255),o.push((a>>>14|128)&255),o.push((a>>>7|128)&255),o.push(a&127))}var r=n.split("."),s=[];s.push(parseInt(r[0],10)*40+parseInt(r[1],10)),r.slice(2).forEach(function(o){e(s,parseInt(o,10))});var i=this;this._ensure(2+s.length),this.writeByte(t),this.writeLength(s.length),s.forEach(function(o){i.writeByte(o)})};qt.prototype.writeLength=function(n){if(typeof n!="number")throw new TypeError("argument must be a Number");if(this._ensure(4),n<=127)this._buf[this._offset++]=n;else if(n<=255)this._buf[this._offset++]=129,this._buf[this._offset++]=n;else if(n<=65535)this._buf[this._offset++]=130,this._buf[this._offset++]=n>>8,this._buf[this._offset++]=n;else if(n<=16777215)this._buf[this._offset++]=131,this._buf[this._offset++]=n>>16,this._buf[this._offset++]=n>>8,this._buf[this._offset++]=n;else throw qi("Length too long (> 4 bytes)")};qt.prototype.startSequence=function(n){typeof n!="number"&&(n=Fn.Sequence|Fn.Constructor),this.writeByte(n),this._seq.push(this._offset),this._ensure(3),this._offset+=3};qt.prototype.endSequence=function(){var n=this._seq.pop(),t=n+3,e=this._offset-t;if(e<=127)this._shift(t,e,-2),this._buf[n]=e;else if(e<=255)this._shift(t,e,-1),this._buf[n]=129,this._buf[n+1]=e;else if(e<=65535)this._buf[n]=130,this._buf[n+1]=e>>8,this._buf[n+2]=e;else if(e<=16777215)this._shift(t,e,1),this._buf[n]=131,this._buf[n+1]=e>>16,this._buf[n+2]=e>>8,this._buf[n+3]=e;else throw qi("Sequence too long")};qt.prototype._shift=function(n,t,e){$n.ok(n!==void 0),$n.ok(t!==void 0),$n.ok(e),this._buf.copy(this._buf,n+e,n,n+t),this._offset+=e};qt.prototype._ensure=function(n){if($n.ok(n),this._size-this._offset<n){var t=this._size*this._options.growthFactor;t-this._offset<n&&(t+=n);var e=Wi.alloc(t);this._buf.copy(e,0,0,this._offset),this._buf=e,this._size=t}};vc.exports=qt});var Bc=at((oE,Gi)=>{var ro=Fi(),io=Hi(),Jh=Cc(),Zh=kc();Gi.exports={Reader:Jh,Writer:Zh};for(Ki in io)io.hasOwnProperty(Ki)&&(Gi.exports[Ki]=io[Ki]);var Ki;for(Vi in ro)ro.hasOwnProperty(Vi)&&(Gi.exports[Vi]=ro[Vi]);var Vi});var ni=at((aE,Rc)=>{var so=Bc();Rc.exports={Ber:so,BerReader:so.Reader,BerWriter:so.Writer}});var Nc=at((cE,Yi)=>{(function(n){"use strict";var t=function(p){var A,m=new Float64Array(16);if(p)for(A=0;A<p.length;A++)m[A]=p[A];return m},e=function(){throw new Error("no PRNG")},r=new Uint8Array(16),s=new Uint8Array(32);s[0]=9;var i=t(),o=t([1]),a=t([56129,1]),c=t([30883,4953,19914,30187,55467,16705,2637,112,59544,30585,16505,36039,65139,11119,27886,20995]),f=t([61785,9906,39828,60374,45398,33411,5274,224,53552,61171,33010,6542,64743,22239,55772,9222]),l=t([54554,36645,11616,51542,42930,38181,51040,26924,56412,64982,57905,49316,21502,52590,14035,8553]),u=t([26200,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214]),h=t([41136,18958,6951,50414,58488,44335,6150,12099,55207,15867,153,11085,57099,20417,9344,11139]);function g(p,A,m,d){p[A]=m>>24&255,p[A+1]=m>>16&255,p[A+2]=m>>8&255,p[A+3]=m&255,p[A+4]=d>>24&255,p[A+5]=d>>16&255,p[A+6]=d>>8&255,p[A+7]=d&255}function y(p,A,m,d,E){var P,$=0;for(P=0;P<E;P++)$|=p[A+P]^m[d+P];return(1&$-1>>>8)-1}function _(p,A,m,d){return y(p,A,m,d,16)}function b(p,A,m,d){return y(p,A,m,d,32)}function C(p,A,m,d){for(var E=d[0]&255|(d[1]&255)<<8|(d[2]&255)<<16|(d[3]&255)<<24,P=m[0]&255|(m[1]&255)<<8|(m[2]&255)<<16|(m[3]&255)<<24,$=m[4]&255|(m[5]&255)<<8|(m[6]&255)<<16|(m[7]&255)<<24,J=m[8]&255|(m[9]&255)<<8|(m[10]&255)<<16|(m[11]&255)<<24,ae=m[12]&255|(m[13]&255)<<8|(m[14]&255)<<16|(m[15]&255)<<24,me=d[4]&255|(d[5]&255)<<8|(d[6]&255)<<16|(d[7]&255)<<24,he=A[0]&255|(A[1]&255)<<8|(A[2]&255)<<16|(A[3]&255)<<24,tt=A[4]&255|(A[5]&255)<<8|(A[6]&255)<<16|(A[7]&255)<<24,ge=A[8]&255|(A[9]&255)<<8|(A[10]&255)<<16|(A[11]&255)<<24,Te=A[12]&255|(A[13]&255)<<8|(A[14]&255)<<16|(A[15]&255)<<24,Le=d[8]&255|(d[9]&255)<<8|(d[10]&255)<<16|(d[11]&255)<<24,Fe=m[16]&255|(m[17]&255)<<8|(m[18]&255)<<16|(m[19]&255)<<24,Me=m[20]&255|(m[21]&255)<<8|(m[22]&255)<<16|(m[23]&255)<<24,Ue=m[24]&255|(m[25]&255)<<8|(m[26]&255)<<16|(m[27]&255)<<24,Oe=m[28]&255|(m[29]&255)<<8|(m[30]&255)<<16|(m[31]&255)<<24,De=d[12]&255|(d[13]&255)<<8|(d[14]&255)<<16|(d[15]&255)<<24,Ae=E,be=P,pe=$,Ee=J,_e=ae,de=me,Q=he,W=tt,ie=ge,j=Te,Z=Le,oe=Fe,Ce=Me,He=Ue,We=Oe,Qe=De,S,Ke=0;Ke<20;Ke+=2)S=Ae+Ce|0,_e^=S<<7|S>>>25,S=_e+Ae|0,ie^=S<<9|S>>>23,S=ie+_e|0,Ce^=S<<13|S>>>19,S=Ce+ie|0,Ae^=S<<18|S>>>14,S=de+be|0,j^=S<<7|S>>>25,S=j+de|0,He^=S<<9|S>>>23,S=He+j|0,be^=S<<13|S>>>19,S=be+He|0,de^=S<<18|S>>>14,S=Z+Q|0,We^=S<<7|S>>>25,S=We+Z|0,pe^=S<<9|S>>>23,S=pe+We|0,Q^=S<<13|S>>>19,S=Q+pe|0,Z^=S<<18|S>>>14,S=Qe+oe|0,Ee^=S<<7|S>>>25,S=Ee+Qe|0,W^=S<<9|S>>>23,S=W+Ee|0,oe^=S<<13|S>>>19,S=oe+W|0,Qe^=S<<18|S>>>14,S=Ae+Ee|0,be^=S<<7|S>>>25,S=be+Ae|0,pe^=S<<9|S>>>23,S=pe+be|0,Ee^=S<<13|S>>>19,S=Ee+pe|0,Ae^=S<<18|S>>>14,S=de+_e|0,Q^=S<<7|S>>>25,S=Q+de|0,W^=S<<9|S>>>23,S=W+Q|0,_e^=S<<13|S>>>19,S=_e+W|0,de^=S<<18|S>>>14,S=Z+j|0,oe^=S<<7|S>>>25,S=oe+Z|0,ie^=S<<9|S>>>23,S=ie+oe|0,j^=S<<13|S>>>19,S=j+ie|0,Z^=S<<18|S>>>14,S=Qe+We|0,Ce^=S<<7|S>>>25,S=Ce+Qe|0,He^=S<<9|S>>>23,S=He+Ce|0,We^=S<<13|S>>>19,S=We+He|0,Qe^=S<<18|S>>>14;Ae=Ae+E|0,be=be+P|0,pe=pe+$|0,Ee=Ee+J|0,_e=_e+ae|0,de=de+me|0,Q=Q+he|0,W=W+tt|0,ie=ie+ge|0,j=j+Te|0,Z=Z+Le|0,oe=oe+Fe|0,Ce=Ce+Me|0,He=He+Ue|0,We=We+Oe|0,Qe=Qe+De|0,p[0]=Ae>>>0&255,p[1]=Ae>>>8&255,p[2]=Ae>>>16&255,p[3]=Ae>>>24&255,p[4]=be>>>0&255,p[5]=be>>>8&255,p[6]=be>>>16&255,p[7]=be>>>24&255,p[8]=pe>>>0&255,p[9]=pe>>>8&255,p[10]=pe>>>16&255,p[11]=pe>>>24&255,p[12]=Ee>>>0&255,p[13]=Ee>>>8&255,p[14]=Ee>>>16&255,p[15]=Ee>>>24&255,p[16]=_e>>>0&255,p[17]=_e>>>8&255,p[18]=_e>>>16&255,p[19]=_e>>>24&255,p[20]=de>>>0&255,p[21]=de>>>8&255,p[22]=de>>>16&255,p[23]=de>>>24&255,p[24]=Q>>>0&255,p[25]=Q>>>8&255,p[26]=Q>>>16&255,p[27]=Q>>>24&255,p[28]=W>>>0&255,p[29]=W>>>8&255,p[30]=W>>>16&255,p[31]=W>>>24&255,p[32]=ie>>>0&255,p[33]=ie>>>8&255,p[34]=ie>>>16&255,p[35]=ie>>>24&255,p[36]=j>>>0&255,p[37]=j>>>8&255,p[38]=j>>>16&255,p[39]=j>>>24&255,p[40]=Z>>>0&255,p[41]=Z>>>8&255,p[42]=Z>>>16&255,p[43]=Z>>>24&255,p[44]=oe>>>0&255,p[45]=oe>>>8&255,p[46]=oe>>>16&255,p[47]=oe>>>24&255,p[48]=Ce>>>0&255,p[49]=Ce>>>8&255,p[50]=Ce>>>16&255,p[51]=Ce>>>24&255,p[52]=He>>>0&255,p[53]=He>>>8&255,p[54]=He>>>16&255,p[55]=He>>>24&255,p[56]=We>>>0&255,p[57]=We>>>8&255,p[58]=We>>>16&255,p[59]=We>>>24&255,p[60]=Qe>>>0&255,p[61]=Qe>>>8&255,p[62]=Qe>>>16&255,p[63]=Qe>>>24&255}function L(p,A,m,d){for(var E=d[0]&255|(d[1]&255)<<8|(d[2]&255)<<16|(d[3]&255)<<24,P=m[0]&255|(m[1]&255)<<8|(m[2]&255)<<16|(m[3]&255)<<24,$=m[4]&255|(m[5]&255)<<8|(m[6]&255)<<16|(m[7]&255)<<24,J=m[8]&255|(m[9]&255)<<8|(m[10]&255)<<16|(m[11]&255)<<24,ae=m[12]&255|(m[13]&255)<<8|(m[14]&255)<<16|(m[15]&255)<<24,me=d[4]&255|(d[5]&255)<<8|(d[6]&255)<<16|(d[7]&255)<<24,he=A[0]&255|(A[1]&255)<<8|(A[2]&255)<<16|(A[3]&255)<<24,tt=A[4]&255|(A[5]&255)<<8|(A[6]&255)<<16|(A[7]&255)<<24,ge=A[8]&255|(A[9]&255)<<8|(A[10]&255)<<16|(A[11]&255)<<24,Te=A[12]&255|(A[13]&255)<<8|(A[14]&255)<<16|(A[15]&255)<<24,Le=d[8]&255|(d[9]&255)<<8|(d[10]&255)<<16|(d[11]&255)<<24,Fe=m[16]&255|(m[17]&255)<<8|(m[18]&255)<<16|(m[19]&255)<<24,Me=m[20]&255|(m[21]&255)<<8|(m[22]&255)<<16|(m[23]&255)<<24,Ue=m[24]&255|(m[25]&255)<<8|(m[26]&255)<<16|(m[27]&255)<<24,Oe=m[28]&255|(m[29]&255)<<8|(m[30]&255)<<16|(m[31]&255)<<24,De=d[12]&255|(d[13]&255)<<8|(d[14]&255)<<16|(d[15]&255)<<24,Ae=E,be=P,pe=$,Ee=J,_e=ae,de=me,Q=he,W=tt,ie=ge,j=Te,Z=Le,oe=Fe,Ce=Me,He=Ue,We=Oe,Qe=De,S,Ke=0;Ke<20;Ke+=2)S=Ae+Ce|0,_e^=S<<7|S>>>25,S=_e+Ae|0,ie^=S<<9|S>>>23,S=ie+_e|0,Ce^=S<<13|S>>>19,S=Ce+ie|0,Ae^=S<<18|S>>>14,S=de+be|0,j^=S<<7|S>>>25,S=j+de|0,He^=S<<9|S>>>23,S=He+j|0,be^=S<<13|S>>>19,S=be+He|0,de^=S<<18|S>>>14,S=Z+Q|0,We^=S<<7|S>>>25,S=We+Z|0,pe^=S<<9|S>>>23,S=pe+We|0,Q^=S<<13|S>>>19,S=Q+pe|0,Z^=S<<18|S>>>14,S=Qe+oe|0,Ee^=S<<7|S>>>25,S=Ee+Qe|0,W^=S<<9|S>>>23,S=W+Ee|0,oe^=S<<13|S>>>19,S=oe+W|0,Qe^=S<<18|S>>>14,S=Ae+Ee|0,be^=S<<7|S>>>25,S=be+Ae|0,pe^=S<<9|S>>>23,S=pe+be|0,Ee^=S<<13|S>>>19,S=Ee+pe|0,Ae^=S<<18|S>>>14,S=de+_e|0,Q^=S<<7|S>>>25,S=Q+de|0,W^=S<<9|S>>>23,S=W+Q|0,_e^=S<<13|S>>>19,S=_e+W|0,de^=S<<18|S>>>14,S=Z+j|0,oe^=S<<7|S>>>25,S=oe+Z|0,ie^=S<<9|S>>>23,S=ie+oe|0,j^=S<<13|S>>>19,S=j+ie|0,Z^=S<<18|S>>>14,S=Qe+We|0,Ce^=S<<7|S>>>25,S=Ce+Qe|0,He^=S<<9|S>>>23,S=He+Ce|0,We^=S<<13|S>>>19,S=We+He|0,Qe^=S<<18|S>>>14;p[0]=Ae>>>0&255,p[1]=Ae>>>8&255,p[2]=Ae>>>16&255,p[3]=Ae>>>24&255,p[4]=de>>>0&255,p[5]=de>>>8&255,p[6]=de>>>16&255,p[7]=de>>>24&255,p[8]=Z>>>0&255,p[9]=Z>>>8&255,p[10]=Z>>>16&255,p[11]=Z>>>24&255,p[12]=Qe>>>0&255,p[13]=Qe>>>8&255,p[14]=Qe>>>16&255,p[15]=Qe>>>24&255,p[16]=Q>>>0&255,p[17]=Q>>>8&255,p[18]=Q>>>16&255,p[19]=Q>>>24&255,p[20]=W>>>0&255,p[21]=W>>>8&255,p[22]=W>>>16&255,p[23]=W>>>24&255,p[24]=ie>>>0&255,p[25]=ie>>>8&255,p[26]=ie>>>16&255,p[27]=ie>>>24&255,p[28]=j>>>0&255,p[29]=j>>>8&255,p[30]=j>>>16&255,p[31]=j>>>24&255}function F(p,A,m,d){C(p,A,m,d)}function k(p,A,m,d){L(p,A,m,d)}var K=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function ee(p,A,m,d,E,P,$){var J=new Uint8Array(16),ae=new Uint8Array(64),me,he;for(he=0;he<16;he++)J[he]=0;for(he=0;he<8;he++)J[he]=P[he];for(;E>=64;){for(F(ae,J,$,K),he=0;he<64;he++)p[A+he]=m[d+he]^ae[he];for(me=1,he=8;he<16;he++)me=me+(J[he]&255)|0,J[he]=me&255,me>>>=8;E-=64,A+=64,d+=64}if(E>0)for(F(ae,J,$,K),he=0;he<E;he++)p[A+he]=m[d+he]^ae[he];return 0}function O(p,A,m,d,E){var P=new Uint8Array(16),$=new Uint8Array(64),J,ae;for(ae=0;ae<16;ae++)P[ae]=0;for(ae=0;ae<8;ae++)P[ae]=d[ae];for(;m>=64;){for(F($,P,E,K),ae=0;ae<64;ae++)p[A+ae]=$[ae];for(J=1,ae=8;ae<16;ae++)J=J+(P[ae]&255)|0,P[ae]=J&255,J>>>=8;m-=64,A+=64}if(m>0)for(F($,P,E,K),ae=0;ae<m;ae++)p[A+ae]=$[ae];return 0}function x(p,A,m,d,E){var P=new Uint8Array(32);k(P,d,E,K);for(var $=new Uint8Array(8),J=0;J<8;J++)$[J]=d[J+16];return O(p,A,m,$,P)}function w(p,A,m,d,E,P,$){var J=new Uint8Array(32);k(J,P,$,K);for(var ae=new Uint8Array(8),me=0;me<8;me++)ae[me]=P[me+16];return ee(p,A,m,d,E,ae,J)}var I=function(p){this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.leftover=0,this.fin=0;var A,m,d,E,P,$,J,ae;A=p[0]&255|(p[1]&255)<<8,this.r[0]=A&8191,m=p[2]&255|(p[3]&255)<<8,this.r[1]=(A>>>13|m<<3)&8191,d=p[4]&255|(p[5]&255)<<8,this.r[2]=(m>>>10|d<<6)&7939,E=p[6]&255|(p[7]&255)<<8,this.r[3]=(d>>>7|E<<9)&8191,P=p[8]&255|(p[9]&255)<<8,this.r[4]=(E>>>4|P<<12)&255,this.r[5]=P>>>1&8190,$=p[10]&255|(p[11]&255)<<8,this.r[6]=(P>>>14|$<<2)&8191,J=p[12]&255|(p[13]&255)<<8,this.r[7]=($>>>11|J<<5)&8065,ae=p[14]&255|(p[15]&255)<<8,this.r[8]=(J>>>8|ae<<8)&8191,this.r[9]=ae>>>5&127,this.pad[0]=p[16]&255|(p[17]&255)<<8,this.pad[1]=p[18]&255|(p[19]&255)<<8,this.pad[2]=p[20]&255|(p[21]&255)<<8,this.pad[3]=p[22]&255|(p[23]&255)<<8,this.pad[4]=p[24]&255|(p[25]&255)<<8,this.pad[5]=p[26]&255|(p[27]&255)<<8,this.pad[6]=p[28]&255|(p[29]&255)<<8,this.pad[7]=p[30]&255|(p[31]&255)<<8};I.prototype.blocks=function(p,A,m){for(var d=this.fin?0:2048,E,P,$,J,ae,me,he,tt,ge,Te,Le,Fe,Me,Ue,Oe,De,Ae,be,pe,Ee=this.h[0],_e=this.h[1],de=this.h[2],Q=this.h[3],W=this.h[4],ie=this.h[5],j=this.h[6],Z=this.h[7],oe=this.h[8],Ce=this.h[9],He=this.r[0],We=this.r[1],Qe=this.r[2],S=this.r[3],Ke=this.r[4],nt=this.r[5],rt=this.r[6],qe=this.r[7],Je=this.r[8],Ze=this.r[9];m>=16;)E=p[A+0]&255|(p[A+1]&255)<<8,Ee+=E&8191,P=p[A+2]&255|(p[A+3]&255)<<8,_e+=(E>>>13|P<<3)&8191,$=p[A+4]&255|(p[A+5]&255)<<8,de+=(P>>>10|$<<6)&8191,J=p[A+6]&255|(p[A+7]&255)<<8,Q+=($>>>7|J<<9)&8191,ae=p[A+8]&255|(p[A+9]&255)<<8,W+=(J>>>4|ae<<12)&8191,ie+=ae>>>1&8191,me=p[A+10]&255|(p[A+11]&255)<<8,j+=(ae>>>14|me<<2)&8191,he=p[A+12]&255|(p[A+13]&255)<<8,Z+=(me>>>11|he<<5)&8191,tt=p[A+14]&255|(p[A+15]&255)<<8,oe+=(he>>>8|tt<<8)&8191,Ce+=tt>>>5|d,ge=0,Te=ge,Te+=Ee*He,Te+=_e*(5*Ze),Te+=de*(5*Je),Te+=Q*(5*qe),Te+=W*(5*rt),ge=Te>>>13,Te&=8191,Te+=ie*(5*nt),Te+=j*(5*Ke),Te+=Z*(5*S),Te+=oe*(5*Qe),Te+=Ce*(5*We),ge+=Te>>>13,Te&=8191,Le=ge,Le+=Ee*We,Le+=_e*He,Le+=de*(5*Ze),Le+=Q*(5*Je),Le+=W*(5*qe),ge=Le>>>13,Le&=8191,Le+=ie*(5*rt),Le+=j*(5*nt),Le+=Z*(5*Ke),Le+=oe*(5*S),Le+=Ce*(5*Qe),ge+=Le>>>13,Le&=8191,Fe=ge,Fe+=Ee*Qe,Fe+=_e*We,Fe+=de*He,Fe+=Q*(5*Ze),Fe+=W*(5*Je),ge=Fe>>>13,Fe&=8191,Fe+=ie*(5*qe),Fe+=j*(5*rt),Fe+=Z*(5*nt),Fe+=oe*(5*Ke),Fe+=Ce*(5*S),ge+=Fe>>>13,Fe&=8191,Me=ge,Me+=Ee*S,Me+=_e*Qe,Me+=de*We,Me+=Q*He,Me+=W*(5*Ze),ge=Me>>>13,Me&=8191,Me+=ie*(5*Je),Me+=j*(5*qe),Me+=Z*(5*rt),Me+=oe*(5*nt),Me+=Ce*(5*Ke),ge+=Me>>>13,Me&=8191,Ue=ge,Ue+=Ee*Ke,Ue+=_e*S,Ue+=de*Qe,Ue+=Q*We,Ue+=W*He,ge=Ue>>>13,Ue&=8191,Ue+=ie*(5*Ze),Ue+=j*(5*Je),Ue+=Z*(5*qe),Ue+=oe*(5*rt),Ue+=Ce*(5*nt),ge+=Ue>>>13,Ue&=8191,Oe=ge,Oe+=Ee*nt,Oe+=_e*Ke,Oe+=de*S,Oe+=Q*Qe,Oe+=W*We,ge=Oe>>>13,Oe&=8191,Oe+=ie*He,Oe+=j*(5*Ze),Oe+=Z*(5*Je),Oe+=oe*(5*qe),Oe+=Ce*(5*rt),ge+=Oe>>>13,Oe&=8191,De=ge,De+=Ee*rt,De+=_e*nt,De+=de*Ke,De+=Q*S,De+=W*Qe,ge=De>>>13,De&=8191,De+=ie*We,De+=j*He,De+=Z*(5*Ze),De+=oe*(5*Je),De+=Ce*(5*qe),ge+=De>>>13,De&=8191,Ae=ge,Ae+=Ee*qe,Ae+=_e*rt,Ae+=de*nt,Ae+=Q*Ke,Ae+=W*S,ge=Ae>>>13,Ae&=8191,Ae+=ie*Qe,Ae+=j*We,Ae+=Z*He,Ae+=oe*(5*Ze),Ae+=Ce*(5*Je),ge+=Ae>>>13,Ae&=8191,be=ge,be+=Ee*Je,be+=_e*qe,be+=de*rt,be+=Q*nt,be+=W*Ke,ge=be>>>13,be&=8191,be+=ie*S,be+=j*Qe,be+=Z*We,be+=oe*He,be+=Ce*(5*Ze),ge+=be>>>13,be&=8191,pe=ge,pe+=Ee*Ze,pe+=_e*Je,pe+=de*qe,pe+=Q*rt,pe+=W*nt,ge=pe>>>13,pe&=8191,pe+=ie*Ke,pe+=j*S,pe+=Z*Qe,pe+=oe*We,pe+=Ce*He,ge+=pe>>>13,pe&=8191,ge=(ge<<2)+ge|0,ge=ge+Te|0,Te=ge&8191,ge=ge>>>13,Le+=ge,Ee=Te,_e=Le,de=Fe,Q=Me,W=Ue,ie=Oe,j=De,Z=Ae,oe=be,Ce=pe,A+=16,m-=16;this.h[0]=Ee,this.h[1]=_e,this.h[2]=de,this.h[3]=Q,this.h[4]=W,this.h[5]=ie,this.h[6]=j,this.h[7]=Z,this.h[8]=oe,this.h[9]=Ce},I.prototype.finish=function(p,A){var m=new Uint16Array(10),d,E,P,$;if(this.leftover){for($=this.leftover,this.buffer[$++]=1;$<16;$++)this.buffer[$]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(d=this.h[1]>>>13,this.h[1]&=8191,$=2;$<10;$++)this.h[$]+=d,d=this.h[$]>>>13,this.h[$]&=8191;for(this.h[0]+=d*5,d=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=d,d=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=d,m[0]=this.h[0]+5,d=m[0]>>>13,m[0]&=8191,$=1;$<10;$++)m[$]=this.h[$]+d,d=m[$]>>>13,m[$]&=8191;for(m[9]-=8192,E=(d^1)-1,$=0;$<10;$++)m[$]&=E;for(E=~E,$=0;$<10;$++)this.h[$]=this.h[$]&E|m[$];for(this.h[0]=(this.h[0]|this.h[1]<<13)&65535,this.h[1]=(this.h[1]>>>3|this.h[2]<<10)&65535,this.h[2]=(this.h[2]>>>6|this.h[3]<<7)&65535,this.h[3]=(this.h[3]>>>9|this.h[4]<<4)&65535,this.h[4]=(this.h[4]>>>12|this.h[5]<<1|this.h[6]<<14)&65535,this.h[5]=(this.h[6]>>>2|this.h[7]<<11)&65535,this.h[6]=(this.h[7]>>>5|this.h[8]<<8)&65535,this.h[7]=(this.h[8]>>>8|this.h[9]<<5)&65535,P=this.h[0]+this.pad[0],this.h[0]=P&65535,$=1;$<8;$++)P=(this.h[$]+this.pad[$]|0)+(P>>>16)|0,this.h[$]=P&65535;p[A+0]=this.h[0]>>>0&255,p[A+1]=this.h[0]>>>8&255,p[A+2]=this.h[1]>>>0&255,p[A+3]=this.h[1]>>>8&255,p[A+4]=this.h[2]>>>0&255,p[A+5]=this.h[2]>>>8&255,p[A+6]=this.h[3]>>>0&255,p[A+7]=this.h[3]>>>8&255,p[A+8]=this.h[4]>>>0&255,p[A+9]=this.h[4]>>>8&255,p[A+10]=this.h[5]>>>0&255,p[A+11]=this.h[5]>>>8&255,p[A+12]=this.h[6]>>>0&255,p[A+13]=this.h[6]>>>8&255,p[A+14]=this.h[7]>>>0&255,p[A+15]=this.h[7]>>>8&255},I.prototype.update=function(p,A,m){var d,E;if(this.leftover){for(E=16-this.leftover,E>m&&(E=m),d=0;d<E;d++)this.buffer[this.leftover+d]=p[A+d];if(m-=E,A+=E,this.leftover+=E,this.leftover<16)return;this.blocks(this.buffer,0,16),this.leftover=0}if(m>=16&&(E=m-m%16,this.blocks(p,A,E),A+=E,m-=E),m){for(d=0;d<m;d++)this.buffer[this.leftover+d]=p[A+d];this.leftover+=m}};function U(p,A,m,d,E,P){var $=new I(P);return $.update(m,d,E),$.finish(p,A),0}function R(p,A,m,d,E,P){var $=new Uint8Array(16);return U($,0,m,d,E,P),_(p,A,$,0)}function re(p,A,m,d,E){var P;if(m<32)return-1;for(w(p,0,A,0,m,d,E),U(p,16,p,32,m-32,p),P=0;P<16;P++)p[P]=0;return 0}function G(p,A,m,d,E){var P,$=new Uint8Array(32);if(m<32||(x($,0,32,d,E),R(A,16,A,32,m-32,$)!==0))return-1;for(w(p,0,A,0,m,d,E),P=0;P<32;P++)p[P]=0;return 0}function Y(p,A){var m;for(m=0;m<16;m++)p[m]=A[m]|0}function te(p){var A,m,d=1;for(A=0;A<16;A++)m=p[A]+d+65535,d=Math.floor(m/65536),p[A]=m-d*65536;p[0]+=d-1+37*(d-1)}function ce(p,A,m){for(var d,E=~(m-1),P=0;P<16;P++)d=E&(p[P]^A[P]),p[P]^=d,A[P]^=d}function D(p,A){var m,d,E,P=t(),$=t();for(m=0;m<16;m++)$[m]=A[m];for(te($),te($),te($),d=0;d<2;d++){for(P[0]=$[0]-65517,m=1;m<15;m++)P[m]=$[m]-65535-(P[m-1]>>16&1),P[m-1]&=65535;P[15]=$[15]-32767-(P[14]>>16&1),E=P[15]>>16&1,P[14]&=65535,ce($,P,1-E)}for(m=0;m<16;m++)p[2*m]=$[m]&255,p[2*m+1]=$[m]>>8}function v(p,A){var m=new Uint8Array(32),d=new Uint8Array(32);return D(m,p),D(d,A),b(m,0,d,0)}function N(p){var A=new Uint8Array(32);return D(A,p),A[0]&1}function H(p,A){var m;for(m=0;m<16;m++)p[m]=A[2*m]+(A[2*m+1]<<8);p[15]&=32767}function X(p,A,m){for(var d=0;d<16;d++)p[d]=A[d]+m[d]}function fe(p,A,m){for(var d=0;d<16;d++)p[d]=A[d]-m[d]}function se(p,A,m){var d,E,P=0,$=0,J=0,ae=0,me=0,he=0,tt=0,ge=0,Te=0,Le=0,Fe=0,Me=0,Ue=0,Oe=0,De=0,Ae=0,be=0,pe=0,Ee=0,_e=0,de=0,Q=0,W=0,ie=0,j=0,Z=0,oe=0,Ce=0,He=0,We=0,Qe=0,S=m[0],Ke=m[1],nt=m[2],rt=m[3],qe=m[4],Je=m[5],Ze=m[6],Ct=m[7],ct=m[8],St=m[9],wt=m[10],It=m[11],Lt=m[12],Ht=m[13],Qt=m[14],Wt=m[15];d=A[0],P+=d*S,$+=d*Ke,J+=d*nt,ae+=d*rt,me+=d*qe,he+=d*Je,tt+=d*Ze,ge+=d*Ct,Te+=d*ct,Le+=d*St,Fe+=d*wt,Me+=d*It,Ue+=d*Lt,Oe+=d*Ht,De+=d*Qt,Ae+=d*Wt,d=A[1],$+=d*S,J+=d*Ke,ae+=d*nt,me+=d*rt,he+=d*qe,tt+=d*Je,ge+=d*Ze,Te+=d*Ct,Le+=d*ct,Fe+=d*St,Me+=d*wt,Ue+=d*It,Oe+=d*Lt,De+=d*Ht,Ae+=d*Qt,be+=d*Wt,d=A[2],J+=d*S,ae+=d*Ke,me+=d*nt,he+=d*rt,tt+=d*qe,ge+=d*Je,Te+=d*Ze,Le+=d*Ct,Fe+=d*ct,Me+=d*St,Ue+=d*wt,Oe+=d*It,De+=d*Lt,Ae+=d*Ht,be+=d*Qt,pe+=d*Wt,d=A[3],ae+=d*S,me+=d*Ke,he+=d*nt,tt+=d*rt,ge+=d*qe,Te+=d*Je,Le+=d*Ze,Fe+=d*Ct,Me+=d*ct,Ue+=d*St,Oe+=d*wt,De+=d*It,Ae+=d*Lt,be+=d*Ht,pe+=d*Qt,Ee+=d*Wt,d=A[4],me+=d*S,he+=d*Ke,tt+=d*nt,ge+=d*rt,Te+=d*qe,Le+=d*Je,Fe+=d*Ze,Me+=d*Ct,Ue+=d*ct,Oe+=d*St,De+=d*wt,Ae+=d*It,be+=d*Lt,pe+=d*Ht,Ee+=d*Qt,_e+=d*Wt,d=A[5],he+=d*S,tt+=d*Ke,ge+=d*nt,Te+=d*rt,Le+=d*qe,Fe+=d*Je,Me+=d*Ze,Ue+=d*Ct,Oe+=d*ct,De+=d*St,Ae+=d*wt,be+=d*It,pe+=d*Lt,Ee+=d*Ht,_e+=d*Qt,de+=d*Wt,d=A[6],tt+=d*S,ge+=d*Ke,Te+=d*nt,Le+=d*rt,Fe+=d*qe,Me+=d*Je,Ue+=d*Ze,Oe+=d*Ct,De+=d*ct,Ae+=d*St,be+=d*wt,pe+=d*It,Ee+=d*Lt,_e+=d*Ht,de+=d*Qt,Q+=d*Wt,d=A[7],ge+=d*S,Te+=d*Ke,Le+=d*nt,Fe+=d*rt,Me+=d*qe,Ue+=d*Je,Oe+=d*Ze,De+=d*Ct,Ae+=d*ct,be+=d*St,pe+=d*wt,Ee+=d*It,_e+=d*Lt,de+=d*Ht,Q+=d*Qt,W+=d*Wt,d=A[8],Te+=d*S,Le+=d*Ke,Fe+=d*nt,Me+=d*rt,Ue+=d*qe,Oe+=d*Je,De+=d*Ze,Ae+=d*Ct,be+=d*ct,pe+=d*St,Ee+=d*wt,_e+=d*It,de+=d*Lt,Q+=d*Ht,W+=d*Qt,ie+=d*Wt,d=A[9],Le+=d*S,Fe+=d*Ke,Me+=d*nt,Ue+=d*rt,Oe+=d*qe,De+=d*Je,Ae+=d*Ze,be+=d*Ct,pe+=d*ct,Ee+=d*St,_e+=d*wt,de+=d*It,Q+=d*Lt,W+=d*Ht,ie+=d*Qt,j+=d*Wt,d=A[10],Fe+=d*S,Me+=d*Ke,Ue+=d*nt,Oe+=d*rt,De+=d*qe,Ae+=d*Je,be+=d*Ze,pe+=d*Ct,Ee+=d*ct,_e+=d*St,de+=d*wt,Q+=d*It,W+=d*Lt,ie+=d*Ht,j+=d*Qt,Z+=d*Wt,d=A[11],Me+=d*S,Ue+=d*Ke,Oe+=d*nt,De+=d*rt,Ae+=d*qe,be+=d*Je,pe+=d*Ze,Ee+=d*Ct,_e+=d*ct,de+=d*St,Q+=d*wt,W+=d*It,ie+=d*Lt,j+=d*Ht,Z+=d*Qt,oe+=d*Wt,d=A[12],Ue+=d*S,Oe+=d*Ke,De+=d*nt,Ae+=d*rt,be+=d*qe,pe+=d*Je,Ee+=d*Ze,_e+=d*Ct,de+=d*ct,Q+=d*St,W+=d*wt,ie+=d*It,j+=d*Lt,Z+=d*Ht,oe+=d*Qt,Ce+=d*Wt,d=A[13],Oe+=d*S,De+=d*Ke,Ae+=d*nt,be+=d*rt,pe+=d*qe,Ee+=d*Je,_e+=d*Ze,de+=d*Ct,Q+=d*ct,W+=d*St,ie+=d*wt,j+=d*It,Z+=d*Lt,oe+=d*Ht,Ce+=d*Qt,He+=d*Wt,d=A[14],De+=d*S,Ae+=d*Ke,be+=d*nt,pe+=d*rt,Ee+=d*qe,_e+=d*Je,de+=d*Ze,Q+=d*Ct,W+=d*ct,ie+=d*St,j+=d*wt,Z+=d*It,oe+=d*Lt,Ce+=d*Ht,He+=d*Qt,We+=d*Wt,d=A[15],Ae+=d*S,be+=d*Ke,pe+=d*nt,Ee+=d*rt,_e+=d*qe,de+=d*Je,Q+=d*Ze,W+=d*Ct,ie+=d*ct,j+=d*St,Z+=d*wt,oe+=d*It,Ce+=d*Lt,He+=d*Ht,We+=d*Qt,Qe+=d*Wt,P+=38*be,$+=38*pe,J+=38*Ee,ae+=38*_e,me+=38*de,he+=38*Q,tt+=38*W,ge+=38*ie,Te+=38*j,Le+=38*Z,Fe+=38*oe,Me+=38*Ce,Ue+=38*He,Oe+=38*We,De+=38*Qe,E=1,d=P+E+65535,E=Math.floor(d/65536),P=d-E*65536,d=$+E+65535,E=Math.floor(d/65536),$=d-E*65536,d=J+E+65535,E=Math.floor(d/65536),J=d-E*65536,d=ae+E+65535,E=Math.floor(d/65536),ae=d-E*65536,d=me+E+65535,E=Math.floor(d/65536),me=d-E*65536,d=he+E+65535,E=Math.floor(d/65536),he=d-E*65536,d=tt+E+65535,E=Math.floor(d/65536),tt=d-E*65536,d=ge+E+65535,E=Math.floor(d/65536),ge=d-E*65536,d=Te+E+65535,E=Math.floor(d/65536),Te=d-E*65536,d=Le+E+65535,E=Math.floor(d/65536),Le=d-E*65536,d=Fe+E+65535,E=Math.floor(d/65536),Fe=d-E*65536,d=Me+E+65535,E=Math.floor(d/65536),Me=d-E*65536,d=Ue+E+65535,E=Math.floor(d/65536),Ue=d-E*65536,d=Oe+E+65535,E=Math.floor(d/65536),Oe=d-E*65536,d=De+E+65535,E=Math.floor(d/65536),De=d-E*65536,d=Ae+E+65535,E=Math.floor(d/65536),Ae=d-E*65536,P+=E-1+37*(E-1),E=1,d=P+E+65535,E=Math.floor(d/65536),P=d-E*65536,d=$+E+65535,E=Math.floor(d/65536),$=d-E*65536,d=J+E+65535,E=Math.floor(d/65536),J=d-E*65536,d=ae+E+65535,E=Math.floor(d/65536),ae=d-E*65536,d=me+E+65535,E=Math.floor(d/65536),me=d-E*65536,d=he+E+65535,E=Math.floor(d/65536),he=d-E*65536,d=tt+E+65535,E=Math.floor(d/65536),tt=d-E*65536,d=ge+E+65535,E=Math.floor(d/65536),ge=d-E*65536,d=Te+E+65535,E=Math.floor(d/65536),Te=d-E*65536,d=Le+E+65535,E=Math.floor(d/65536),Le=d-E*65536,d=Fe+E+65535,E=Math.floor(d/65536),Fe=d-E*65536,d=Me+E+65535,E=Math.floor(d/65536),Me=d-E*65536,d=Ue+E+65535,E=Math.floor(d/65536),Ue=d-E*65536,d=Oe+E+65535,E=Math.floor(d/65536),Oe=d-E*65536,d=De+E+65535,E=Math.floor(d/65536),De=d-E*65536,d=Ae+E+65535,E=Math.floor(d/65536),Ae=d-E*65536,P+=E-1+37*(E-1),p[0]=P,p[1]=$,p[2]=J,p[3]=ae,p[4]=me,p[5]=he,p[6]=tt,p[7]=ge,p[8]=Te,p[9]=Le,p[10]=Fe,p[11]=Me,p[12]=Ue,p[13]=Oe,p[14]=De,p[15]=Ae}function ze(p,A){se(p,A,A)}function _t(p,A){var m=t(),d;for(d=0;d<16;d++)m[d]=A[d];for(d=253;d>=0;d--)ze(m,m),d!==2&&d!==4&&se(m,m,A);for(d=0;d<16;d++)p[d]=m[d]}function An(p,A){var m=t(),d;for(d=0;d<16;d++)m[d]=A[d];for(d=250;d>=0;d--)ze(m,m),d!==1&&se(m,m,A);for(d=0;d<16;d++)p[d]=m[d]}function pr(p,A,m){var d=new Uint8Array(32),E=new Float64Array(80),P,$,J=t(),ae=t(),me=t(),he=t(),tt=t(),ge=t();for($=0;$<31;$++)d[$]=A[$];for(d[31]=A[31]&127|64,d[0]&=248,H(E,m),$=0;$<16;$++)ae[$]=E[$],he[$]=J[$]=me[$]=0;for(J[0]=he[0]=1,$=254;$>=0;--$)P=d[$>>>3]>>>($&7)&1,ce(J,ae,P),ce(me,he,P),X(tt,J,me),fe(J,J,me),X(me,ae,he),fe(ae,ae,he),ze(he,tt),ze(ge,J),se(J,me,J),se(me,ae,tt),X(tt,J,me),fe(J,J,me),ze(ae,J),fe(me,he,ge),se(J,me,a),X(J,J,he),se(me,me,J),se(J,he,ge),se(he,ae,E),ze(ae,tt),ce(J,ae,P),ce(me,he,P);for($=0;$<16;$++)E[$+16]=J[$],E[$+32]=me[$],E[$+48]=ae[$],E[$+64]=he[$];var Te=E.subarray(32),Le=E.subarray(16);return _t(Te,Te),se(Le,Le,Te),D(p,Le),0}function gr(p,A){return pr(p,A,s)}function kn(p,A){return e(A,32),gr(p,A)}function mr(p,A,m){var d=new Uint8Array(32);return pr(d,m,A),k(p,r,d,K)}var jr=re,Mi=G;function Xr(p,A,m,d,E,P){var $=new Uint8Array(32);return mr($,E,P),jr(p,A,m,d,$)}function Ar(p,A,m,d,E,P){var $=new Uint8Array(32);return mr($,E,P),Mi(p,A,m,d,$)}var Er=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591];function z(p,A,m,d){for(var E=new Int32Array(16),P=new Int32Array(16),$,J,ae,me,he,tt,ge,Te,Le,Fe,Me,Ue,Oe,De,Ae,be,pe,Ee,_e,de,Q,W,ie,j,Z,oe,Ce=p[0],He=p[1],We=p[2],Qe=p[3],S=p[4],Ke=p[5],nt=p[6],rt=p[7],qe=A[0],Je=A[1],Ze=A[2],Ct=A[3],ct=A[4],St=A[5],wt=A[6],It=A[7],Lt=0;d>=128;){for(_e=0;_e<16;_e++)de=8*_e+Lt,E[_e]=m[de+0]<<24|m[de+1]<<16|m[de+2]<<8|m[de+3],P[_e]=m[de+4]<<24|m[de+5]<<16|m[de+6]<<8|m[de+7];for(_e=0;_e<80;_e++)if($=Ce,J=He,ae=We,me=Qe,he=S,tt=Ke,ge=nt,Te=rt,Le=qe,Fe=Je,Me=Ze,Ue=Ct,Oe=ct,De=St,Ae=wt,be=It,Q=rt,W=It,ie=W&65535,j=W>>>16,Z=Q&65535,oe=Q>>>16,Q=(S>>>14|ct<<18)^(S>>>18|ct<<14)^(ct>>>9|S<<23),W=(ct>>>14|S<<18)^(ct>>>18|S<<14)^(S>>>9|ct<<23),ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,Q=S&Ke^~S&nt,W=ct&St^~ct&wt,ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,Q=Er[_e*2],W=Er[_e*2+1],ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,Q=E[_e%16],W=P[_e%16],ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,j+=ie>>>16,Z+=j>>>16,oe+=Z>>>16,pe=Z&65535|oe<<16,Ee=ie&65535|j<<16,Q=pe,W=Ee,ie=W&65535,j=W>>>16,Z=Q&65535,oe=Q>>>16,Q=(Ce>>>28|qe<<4)^(qe>>>2|Ce<<30)^(qe>>>7|Ce<<25),W=(qe>>>28|Ce<<4)^(Ce>>>2|qe<<30)^(Ce>>>7|qe<<25),ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,Q=Ce&He^Ce&We^He&We,W=qe&Je^qe&Ze^Je&Ze,ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,j+=ie>>>16,Z+=j>>>16,oe+=Z>>>16,Te=Z&65535|oe<<16,be=ie&65535|j<<16,Q=me,W=Ue,ie=W&65535,j=W>>>16,Z=Q&65535,oe=Q>>>16,Q=pe,W=Ee,ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,j+=ie>>>16,Z+=j>>>16,oe+=Z>>>16,me=Z&65535|oe<<16,Ue=ie&65535|j<<16,He=$,We=J,Qe=ae,S=me,Ke=he,nt=tt,rt=ge,Ce=Te,Je=Le,Ze=Fe,Ct=Me,ct=Ue,St=Oe,wt=De,It=Ae,qe=be,_e%16===15)for(de=0;de<16;de++)Q=E[de],W=P[de],ie=W&65535,j=W>>>16,Z=Q&65535,oe=Q>>>16,Q=E[(de+9)%16],W=P[(de+9)%16],ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,pe=E[(de+1)%16],Ee=P[(de+1)%16],Q=(pe>>>1|Ee<<31)^(pe>>>8|Ee<<24)^pe>>>7,W=(Ee>>>1|pe<<31)^(Ee>>>8|pe<<24)^(Ee>>>7|pe<<25),ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,pe=E[(de+14)%16],Ee=P[(de+14)%16],Q=(pe>>>19|Ee<<13)^(Ee>>>29|pe<<3)^pe>>>6,W=(Ee>>>19|pe<<13)^(pe>>>29|Ee<<3)^(Ee>>>6|pe<<26),ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,j+=ie>>>16,Z+=j>>>16,oe+=Z>>>16,E[de]=Z&65535|oe<<16,P[de]=ie&65535|j<<16;Q=Ce,W=qe,ie=W&65535,j=W>>>16,Z=Q&65535,oe=Q>>>16,Q=p[0],W=A[0],ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,j+=ie>>>16,Z+=j>>>16,oe+=Z>>>16,p[0]=Ce=Z&65535|oe<<16,A[0]=qe=ie&65535|j<<16,Q=He,W=Je,ie=W&65535,j=W>>>16,Z=Q&65535,oe=Q>>>16,Q=p[1],W=A[1],ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,j+=ie>>>16,Z+=j>>>16,oe+=Z>>>16,p[1]=He=Z&65535|oe<<16,A[1]=Je=ie&65535|j<<16,Q=We,W=Ze,ie=W&65535,j=W>>>16,Z=Q&65535,oe=Q>>>16,Q=p[2],W=A[2],ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,j+=ie>>>16,Z+=j>>>16,oe+=Z>>>16,p[2]=We=Z&65535|oe<<16,A[2]=Ze=ie&65535|j<<16,Q=Qe,W=Ct,ie=W&65535,j=W>>>16,Z=Q&65535,oe=Q>>>16,Q=p[3],W=A[3],ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,j+=ie>>>16,Z+=j>>>16,oe+=Z>>>16,p[3]=Qe=Z&65535|oe<<16,A[3]=Ct=ie&65535|j<<16,Q=S,W=ct,ie=W&65535,j=W>>>16,Z=Q&65535,oe=Q>>>16,Q=p[4],W=A[4],ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,j+=ie>>>16,Z+=j>>>16,oe+=Z>>>16,p[4]=S=Z&65535|oe<<16,A[4]=ct=ie&65535|j<<16,Q=Ke,W=St,ie=W&65535,j=W>>>16,Z=Q&65535,oe=Q>>>16,Q=p[5],W=A[5],ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,j+=ie>>>16,Z+=j>>>16,oe+=Z>>>16,p[5]=Ke=Z&65535|oe<<16,A[5]=St=ie&65535|j<<16,Q=nt,W=wt,ie=W&65535,j=W>>>16,Z=Q&65535,oe=Q>>>16,Q=p[6],W=A[6],ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,j+=ie>>>16,Z+=j>>>16,oe+=Z>>>16,p[6]=nt=Z&65535|oe<<16,A[6]=wt=ie&65535|j<<16,Q=rt,W=It,ie=W&65535,j=W>>>16,Z=Q&65535,oe=Q>>>16,Q=p[7],W=A[7],ie+=W&65535,j+=W>>>16,Z+=Q&65535,oe+=Q>>>16,j+=ie>>>16,Z+=j>>>16,oe+=Z>>>16,p[7]=rt=Z&65535|oe<<16,A[7]=It=ie&65535|j<<16,Lt+=128,d-=128}return d}function ue(p,A,m){var d=new Int32Array(8),E=new Int32Array(8),P=new Uint8Array(256),$,J=m;for(d[0]=1779033703,d[1]=3144134277,d[2]=1013904242,d[3]=2773480762,d[4]=1359893119,d[5]=2600822924,d[6]=528734635,d[7]=1541459225,E[0]=4089235720,E[1]=2227873595,E[2]=4271175723,E[3]=1595750129,E[4]=2917565137,E[5]=725511199,E[6]=4215389547,E[7]=327033209,z(d,E,A,m),m%=128,$=0;$<m;$++)P[$]=A[J-m+$];for(P[m]=128,m=256-128*(m<112?1:0),P[m-9]=0,g(P,m-8,J/536870912|0,J<<3),z(d,E,P,m),$=0;$<8;$++)g(p,8*$,d[$],E[$]);return 0}function xe(p,A){var m=t(),d=t(),E=t(),P=t(),$=t(),J=t(),ae=t(),me=t(),he=t();fe(m,p[1],p[0]),fe(he,A[1],A[0]),se(m,m,he),X(d,p[0],p[1]),X(he,A[0],A[1]),se(d,d,he),se(E,p[3],A[3]),se(E,E,f),se(P,p[2],A[2]),X(P,P,P),fe($,d,m),fe(J,P,E),X(ae,P,E),X(me,d,m),se(p[0],$,J),se(p[1],me,ae),se(p[2],ae,J),se(p[3],$,me)}function Pe(p,A,m){var d;for(d=0;d<4;d++)ce(p[d],A[d],m)}function je(p,A){var m=t(),d=t(),E=t();_t(E,A[2]),se(m,A[0],E),se(d,A[1],E),D(p,d),p[31]^=N(m)<<7}function Nt(p,A,m){var d,E;for(Y(p[0],i),Y(p[1],o),Y(p[2],o),Y(p[3],i),E=255;E>=0;--E)d=m[E/8|0]>>(E&7)&1,Pe(p,A,d),xe(A,p),xe(p,p),Pe(p,A,d)}function En(p,A){var m=[t(),t(),t(),t()];Y(m[0],l),Y(m[1],u),Y(m[2],o),se(m[3],l,u),Nt(p,m,A)}function tn(p,A,m){var d=new Uint8Array(64),E=[t(),t(),t(),t()],P;for(m||e(A,32),ue(d,A,32),d[0]&=248,d[31]&=127,d[31]|=64,En(E,d),je(p,E),P=0;P<32;P++)A[P+32]=p[P];return 0}var _r=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function ot(p,A){var m,d,E,P;for(d=63;d>=32;--d){for(m=0,E=d-32,P=d-12;E<P;++E)A[E]+=m-16*A[d]*_r[E-(d-32)],m=A[E]+128>>8,A[E]-=m*256;A[E]+=m,A[d]=0}for(m=0,E=0;E<32;E++)A[E]+=m-(A[31]>>4)*_r[E],m=A[E]>>8,A[E]&=255;for(E=0;E<32;E++)A[E]-=m*_r[E];for(d=0;d<32;d++)A[d+1]+=A[d]>>8,p[d]=A[d]&255}function Ut(p){var A=new Float64Array(64),m;for(m=0;m<64;m++)A[m]=p[m];for(m=0;m<64;m++)p[m]=0;ot(p,A)}function Tt(p,A,m,d){var E=new Uint8Array(64),P=new Uint8Array(64),$=new Uint8Array(64),J,ae,me=new Float64Array(64),he=[t(),t(),t(),t()];ue(E,d,32),E[0]&=248,E[31]&=127,E[31]|=64;var tt=m+64;for(J=0;J<m;J++)p[64+J]=A[J];for(J=0;J<32;J++)p[32+J]=E[32+J];for(ue($,p.subarray(32),m+32),Ut($),En(he,$),je(p,he),J=32;J<64;J++)p[J]=d[J];for(ue(P,p,m+64),Ut(P),J=0;J<64;J++)me[J]=0;for(J=0;J<32;J++)me[J]=$[J];for(J=0;J<32;J++)for(ae=0;ae<32;ae++)me[J+ae]+=P[J]*E[ae];return ot(p.subarray(32),me),tt}function bt(p,A){var m=t(),d=t(),E=t(),P=t(),$=t(),J=t(),ae=t();return Y(p[2],o),H(p[1],A),ze(E,p[1]),se(P,E,c),fe(E,E,p[2]),X(P,p[2],P),ze($,P),ze(J,$),se(ae,J,$),se(m,ae,E),se(m,m,P),An(m,m),se(m,m,E),se(m,m,P),se(m,m,P),se(p[0],m,P),ze(d,p[0]),se(d,d,P),v(d,E)&&se(p[0],p[0],h),ze(d,p[0]),se(d,d,P),v(d,E)?-1:(N(p[0])===A[31]>>7&&fe(p[0],i,p[0]),se(p[3],p[0],p[1]),0)}function ut(p,A,m,d){var E,P,$=new Uint8Array(32),J=new Uint8Array(64),ae=[t(),t(),t(),t()],me=[t(),t(),t(),t()];if(P=-1,m<64||bt(me,d))return-1;for(E=0;E<m;E++)p[E]=A[E];for(E=0;E<32;E++)p[E+32]=d[E];if(ue(J,p,m),Ut(J),Nt(ae,me,J),En(me,A.subarray(32)),xe(ae,me),je($,ae),m-=64,b(A,0,$,0)){for(E=0;E<m;E++)p[E]=0;return-1}for(E=0;E<m;E++)p[E]=A[E+64];return P=m,P}var an=32,xt=24,tr=32,yr=16,Jr=32,$i=32,Zr=32,ei=32,Zs=32,Ac=xt,Mh=tr,$h=yr,Bn=64,nr=32,br=64,eo=32,to=64;n.lowlevel={crypto_core_hsalsa20:k,crypto_stream_xor:w,crypto_stream:x,crypto_stream_salsa20_xor:ee,crypto_stream_salsa20:O,crypto_onetimeauth:U,crypto_onetimeauth_verify:R,crypto_verify_16:_,crypto_verify_32:b,crypto_secretbox:re,crypto_secretbox_open:G,crypto_scalarmult:pr,crypto_scalarmult_base:gr,crypto_box_beforenm:mr,crypto_box_afternm:jr,crypto_box:Xr,crypto_box_open:Ar,crypto_box_keypair:kn,crypto_hash:ue,crypto_sign:Tt,crypto_sign_keypair:tn,crypto_sign_open:ut,crypto_secretbox_KEYBYTES:an,crypto_secretbox_NONCEBYTES:xt,crypto_secretbox_ZEROBYTES:tr,crypto_secretbox_BOXZEROBYTES:yr,crypto_scalarmult_BYTES:Jr,crypto_scalarmult_SCALARBYTES:$i,crypto_box_PUBLICKEYBYTES:Zr,crypto_box_SECRETKEYBYTES:ei,crypto_box_BEFORENMBYTES:Zs,crypto_box_NONCEBYTES:Ac,crypto_box_ZEROBYTES:Mh,crypto_box_BOXZEROBYTES:$h,crypto_sign_BYTES:Bn,crypto_sign_PUBLICKEYBYTES:nr,crypto_sign_SECRETKEYBYTES:br,crypto_sign_SEEDBYTES:eo,crypto_hash_BYTES:to};function Ec(p,A){if(p.length!==an)throw new Error("bad key size");if(A.length!==xt)throw new Error("bad nonce size")}function Fh(p,A){if(p.length!==Zr)throw new Error("bad public key size");if(A.length!==ei)throw new Error("bad secret key size")}function nn(){var p,A;for(A=0;A<arguments.length;A++)if((p=Object.prototype.toString.call(arguments[A]))!=="[object Uint8Array]")throw new TypeError("unexpected type "+p+", use Uint8Array")}function _c(p){for(var A=0;A<p.length;A++)p[A]=0}n.util||(n.util={},n.util.decodeUTF8=n.util.encodeUTF8=n.util.encodeBase64=n.util.decodeBase64=function(){throw new Error("nacl.util moved into separate package: https://github.com/dchest/tweetnacl-util-js")}),n.randomBytes=function(p){var A=new Uint8Array(p);return e(A,p),A},n.secretbox=function(p,A,m){nn(p,A,m),Ec(m,A);for(var d=new Uint8Array(tr+p.length),E=new Uint8Array(d.length),P=0;P<p.length;P++)d[P+tr]=p[P];return re(E,d,d.length,A,m),E.subarray(yr)},n.secretbox.open=function(p,A,m){nn(p,A,m),Ec(m,A);for(var d=new Uint8Array(yr+p.length),E=new Uint8Array(d.length),P=0;P<p.length;P++)d[P+yr]=p[P];return d.length<32||G(E,d,d.length,A,m)!==0?!1:E.subarray(tr)},n.secretbox.keyLength=an,n.secretbox.nonceLength=xt,n.secretbox.overheadLength=yr,n.scalarMult=function(p,A){if(nn(p,A),p.length!==$i)throw new Error("bad n size");if(A.length!==Jr)throw new Error("bad p size");var m=new Uint8Array(Jr);return pr(m,p,A),m},n.scalarMult.base=function(p){if(nn(p),p.length!==$i)throw new Error("bad n size");var A=new Uint8Array(Jr);return gr(A,p),A},n.scalarMult.scalarLength=$i,n.scalarMult.groupElementLength=Jr,n.box=function(p,A,m,d){var E=n.box.before(m,d);return n.secretbox(p,A,E)},n.box.before=function(p,A){nn(p,A),Fh(p,A);var m=new Uint8Array(Zs);return mr(m,p,A),m},n.box.after=n.secretbox,n.box.open=function(p,A,m,d){var E=n.box.before(m,d);return n.secretbox.open(p,A,E)},n.box.open.after=n.secretbox.open,n.box.keyPair=function(){var p=new Uint8Array(Zr),A=new Uint8Array(ei);return kn(p,A),{publicKey:p,secretKey:A}},n.box.keyPair.fromSecretKey=function(p){if(nn(p),p.length!==ei)throw new Error("bad secret key size");var A=new Uint8Array(Zr);return gr(A,p),{publicKey:A,secretKey:new Uint8Array(p)}},n.box.publicKeyLength=Zr,n.box.secretKeyLength=ei,n.box.sharedKeyLength=Zs,n.box.nonceLength=Ac,n.box.overheadLength=n.secretbox.overheadLength,n.sign=function(p,A){if(nn(p,A),A.length!==br)throw new Error("bad secret key size");var m=new Uint8Array(Bn+p.length);return Tt(m,p,p.length,A),m},n.sign.open=function(p,A){if(arguments.length!==2)throw new Error("nacl.sign.open accepts 2 arguments; did you mean to use nacl.sign.detached.verify?");if(nn(p,A),A.length!==nr)throw new Error("bad public key size");var m=new Uint8Array(p.length),d=ut(m,p,p.length,A);if(d<0)return null;for(var E=new Uint8Array(d),P=0;P<E.length;P++)E[P]=m[P];return E},n.sign.detached=function(p,A){for(var m=n.sign(p,A),d=new Uint8Array(Bn),E=0;E<d.length;E++)d[E]=m[E];return d},n.sign.detached.verify=function(p,A,m){if(nn(p,A,m),A.length!==Bn)throw new Error("bad signature size");if(m.length!==nr)throw new Error("bad public key size");var d=new Uint8Array(Bn+p.length),E=new Uint8Array(Bn+p.length),P;for(P=0;P<Bn;P++)d[P]=A[P];for(P=0;P<p.length;P++)d[P+Bn]=p[P];return ut(E,d,d.length,m)>=0},n.sign.keyPair=function(){var p=new Uint8Array(nr),A=new Uint8Array(br);return tn(p,A),{publicKey:p,secretKey:A}},n.sign.keyPair.fromSecretKey=function(p){if(nn(p),p.length!==br)throw new Error("bad secret key size");for(var A=new Uint8Array(nr),m=0;m<A.length;m++)A[m]=p[32+m];return{publicKey:A,secretKey:new Uint8Array(p)}},n.sign.keyPair.fromSeed=function(p){if(nn(p),p.length!==eo)throw new Error("bad seed size");for(var A=new Uint8Array(nr),m=new Uint8Array(br),d=0;d<32;d++)m[d]=p[d];return tn(A,m,!0),{publicKey:A,secretKey:m}},n.sign.publicKeyLength=nr,n.sign.secretKeyLength=br,n.sign.seedLength=eo,n.sign.signatureLength=Bn,n.hash=function(p){nn(p);var A=new Uint8Array(to);return ue(A,p,p.length),A},n.hash.hashLength=to,n.verify=function(p,A){return nn(p,A),p.length===0||A.length===0||p.length!==A.length?!1:y(p,0,A,0,p.length)===0},n.setPRNG=function(p){e=p},(function(){var p=typeof self<"u"?self.crypto||self.msCrypto:null;if(p&&p.getRandomValues){var A=65536;n.setPRNG(function(m,d){var E,P=new Uint8Array(d);for(E=0;E<d;E+=A)p.getRandomValues(P.subarray(E,E+Math.min(d-E,A)));for(E=0;E<d;E++)m[E]=P[E];_c(P)})}else typeof require<"u"&&(p=require("crypto"),p&&p.randomBytes&&n.setPRNG(function(m,d){var E,P=p.randomBytes(d);for(E=0;E<d;E++)m[E]=P[E];_c(P)}))})()})(typeof Yi<"u"&&Yi.exports?Yi.exports:self.nacl=self.nacl||{})});var fo=at((fE,Pc)=>{"use strict";var oo=Nc().lowlevel.crypto_hash,Rn=0,ir=function(){this.S=[new Uint32Array([3509652390,2564797868,805139163,3491422135,3101798381,1780907670,3128725573,4046225305,614570311,3012652279,134345442,2240740374,1667834072,1901547113,2757295779,4103290238,227898511,1921955416,1904987480,2182433518,2069144605,3260701109,2620446009,720527379,3318853667,677414384,3393288472,3101374703,2390351024,1614419982,1822297739,2954791486,3608508353,3174124327,2024746970,1432378464,3864339955,2857741204,1464375394,1676153920,1439316330,715854006,3033291828,289532110,2706671279,2087905683,3018724369,1668267050,732546397,1947742710,3462151702,2609353502,2950085171,1814351708,2050118529,680887927,999245976,1800124847,3300911131,1713906067,1641548236,4213287313,1216130144,1575780402,4018429277,3917837745,3693486850,3949271944,596196993,3549867205,258830323,2213823033,772490370,2760122372,1774776394,2652871518,566650946,4142492826,1728879713,2882767088,1783734482,3629395816,2517608232,2874225571,1861159788,326777828,3124490320,2130389656,2716951837,967770486,1724537150,2185432712,2364442137,1164943284,2105845187,998989502,3765401048,2244026483,1075463327,1455516326,1322494562,910128902,469688178,1117454909,936433444,3490320968,3675253459,1240580251,122909385,2157517691,634681816,4142456567,3825094682,3061402683,2540495037,79693498,3249098678,1084186820,1583128258,426386531,1761308591,1047286709,322548459,995290223,1845252383,2603652396,3431023940,2942221577,3202600964,3727903485,1712269319,422464435,3234572375,1170764815,3523960633,3117677531,1434042557,442511882,3600875718,1076654713,1738483198,4213154764,2393238008,3677496056,1014306527,4251020053,793779912,2902807211,842905082,4246964064,1395751752,1040244610,2656851899,3396308128,445077038,3742853595,3577915638,679411651,2892444358,2354009459,1767581616,3150600392,3791627101,3102740896,284835224,4246832056,1258075500,768725851,2589189241,3069724005,3532540348,1274779536,3789419226,2764799539,1660621633,3471099624,4011903706,913787905,3497959166,737222580,2514213453,2928710040,3937242737,1804850592,3499020752,2949064160,2386320175,2390070455,2415321851,4061277028,2290661394,2416832540,1336762016,1754252060,3520065937,3014181293,791618072,3188594551,3933548030,2332172193,3852520463,3043980520,413987798,3465142937,3030929376,4245938359,2093235073,3534596313,375366246,2157278981,2479649556,555357303,3870105701,2008414854,3344188149,4221384143,3956125452,2067696032,3594591187,2921233993,2428461,544322398,577241275,1471733935,610547355,4027169054,1432588573,1507829418,2025931657,3646575487,545086370,48609733,2200306550,1653985193,298326376,1316178497,3007786442,2064951626,458293330,2589141269,3591329599,3164325604,727753846,2179363840,146436021,1461446943,4069977195,705550613,3059967265,3887724982,4281599278,3313849956,1404054877,2845806497,146425753,1854211946]),new Uint32Array([1266315497,3048417604,3681880366,3289982499,290971e4,1235738493,2632868024,2414719590,3970600049,1771706367,1449415276,3266420449,422970021,1963543593,2690192192,3826793022,1062508698,1531092325,1804592342,2583117782,2714934279,4024971509,1294809318,4028980673,1289560198,2221992742,1669523910,35572830,157838143,1052438473,1016535060,1802137761,1753167236,1386275462,3080475397,2857371447,1040679964,2145300060,2390574316,1461121720,2956646967,4031777805,4028374788,33600511,2920084762,1018524850,629373528,3691585981,3515945977,2091462646,2486323059,586499841,988145025,935516892,3367335476,2599673255,2839830854,265290510,3972581182,2759138881,3795373465,1005194799,847297441,406762289,1314163512,1332590856,1866599683,4127851711,750260880,613907577,1450815602,3165620655,3734664991,3650291728,3012275730,3704569646,1427272223,778793252,1343938022,2676280711,2052605720,1946737175,3164576444,3914038668,3967478842,3682934266,1661551462,3294938066,4011595847,840292616,3712170807,616741398,312560963,711312465,1351876610,322626781,1910503582,271666773,2175563734,1594956187,70604529,3617834859,1007753275,1495573769,4069517037,2549218298,2663038764,504708206,2263041392,3941167025,2249088522,1514023603,1998579484,1312622330,694541497,2582060303,2151582166,1382467621,776784248,2618340202,3323268794,2497899128,2784771155,503983604,4076293799,907881277,423175695,432175456,1378068232,4145222326,3954048622,3938656102,3820766613,2793130115,2977904593,26017576,3274890735,3194772133,1700274565,1756076034,4006520079,3677328699,720338349,1533947780,354530856,688349552,3973924725,1637815568,332179504,3949051286,53804574,2852348879,3044236432,1282449977,3583942155,3416972820,4006381244,1617046695,2628476075,3002303598,1686838959,431878346,2686675385,1700445008,1080580658,1009431731,832498133,3223435511,2605976345,2271191193,2516031870,1648197032,4164389018,2548247927,300782431,375919233,238389289,3353747414,2531188641,2019080857,1475708069,455242339,2609103871,448939670,3451063019,1395535956,2413381860,1841049896,1491858159,885456874,4264095073,4001119347,1565136089,3898914787,1108368660,540939232,1173283510,2745871338,3681308437,4207628240,3343053890,4016749493,1699691293,1103962373,3625875870,2256883143,3830138730,1031889488,3479347698,1535977030,4236805024,3251091107,2132092099,1774941330,1199868427,1452454533,157007616,2904115357,342012276,595725824,1480756522,206960106,497939518,591360097,863170706,2375253569,3596610801,1814182875,2094937945,3421402208,1082520231,3463918190,2785509508,435703966,3908032597,1641649973,2842273706,3305899714,1510255612,2148256476,2655287854,3276092548,4258621189,236887753,3681803219,274041037,1734335097,3815195456,3317970021,1899903192,1026095262,4050517792,356393447,2410691914,3873677099,3682840055]),new Uint32Array([3913112168,2491498743,4132185628,2489919796,1091903735,1979897079,3170134830,3567386728,3557303409,857797738,1136121015,1342202287,507115054,2535736646,337727348,3213592640,1301675037,2528481711,1895095763,1721773893,3216771564,62756741,2142006736,835421444,2531993523,1442658625,3659876326,2882144922,676362277,1392781812,170690266,3921047035,1759253602,3611846912,1745797284,664899054,1329594018,3901205900,3045908486,2062866102,2865634940,3543621612,3464012697,1080764994,553557557,3656615353,3996768171,991055499,499776247,1265440854,648242737,3940784050,980351604,3713745714,1749149687,3396870395,4211799374,3640570775,1161844396,3125318951,1431517754,545492359,4268468663,3499529547,1437099964,2702547544,3433638243,2581715763,2787789398,1060185593,1593081372,2418618748,4260947970,69676912,2159744348,86519011,2512459080,3838209314,1220612927,3339683548,133810670,1090789135,1078426020,1569222167,845107691,3583754449,4072456591,1091646820,628848692,1613405280,3757631651,526609435,236106946,48312990,2942717905,3402727701,1797494240,859738849,992217954,4005476642,2243076622,3870952857,3732016268,765654824,3490871365,2511836413,1685915746,3888969200,1414112111,2273134842,3281911079,4080962846,172450625,2569994100,980381355,4109958455,2819808352,2716589560,2568741196,3681446669,3329971472,1835478071,660984891,3704678404,4045999559,3422617507,3040415634,1762651403,1719377915,3470491036,2693910283,3642056355,3138596744,1364962596,2073328063,1983633131,926494387,3423689081,2150032023,4096667949,1749200295,3328846651,309677260,2016342300,1779581495,3079819751,111262694,1274766160,443224088,298511866,1025883608,3806446537,1145181785,168956806,3641502830,3584813610,1689216846,3666258015,3200248200,1692713982,2646376535,4042768518,1618508792,1610833997,3523052358,4130873264,2001055236,3610705100,2202168115,4028541809,2961195399,1006657119,2006996926,3186142756,1430667929,3210227297,1314452623,4074634658,4101304120,2273951170,1399257539,3367210612,3027628629,1190975929,2062231137,2333990788,2221543033,2438960610,1181637006,548689776,2362791313,3372408396,3104550113,3145860560,296247880,1970579870,3078560182,3769228297,1714227617,3291629107,3898220290,166772364,1251581989,493813264,448347421,195405023,2709975567,677966185,3703036547,1463355134,2715995803,1338867538,1343315457,2802222074,2684532164,233230375,2599980071,2000651841,3277868038,1638401717,4028070440,3237316320,6314154,819756386,300326615,590932579,1405279636,3267499572,3150704214,2428286686,3959192993,3461946742,1862657033,1266418056,963775037,2089974820,2263052895,1917689273,448879540,3550394620,3981727096,150775221,3627908307,1303187396,508620638,2975983352,2726630617,1817252668,1876281319,1457606340,908771278,3720792119,3617206836,2455994898,1729034894,1080033504]),new Uint32Array([976866871,3556439503,2881648439,1522871579,1555064734,1336096578,3548522304,2579274686,3574697629,3205460757,3593280638,3338716283,3079412587,564236357,2993598910,1781952180,1464380207,3163844217,3332601554,1699332808,1393555694,1183702653,3581086237,1288719814,691649499,2847557200,2895455976,3193889540,2717570544,1781354906,1676643554,2592534050,3230253752,1126444790,2770207658,2633158820,2210423226,2615765581,2414155088,3127139286,673620729,2805611233,1269405062,4015350505,3341807571,4149409754,1057255273,2012875353,2162469141,2276492801,2601117357,993977747,3918593370,2654263191,753973209,36408145,2530585658,25011837,3520020182,2088578344,530523599,2918365339,1524020338,1518925132,3760827505,3759777254,1202760957,3985898139,3906192525,674977740,4174734889,2031300136,2019492241,3983892565,4153806404,3822280332,352677332,2297720250,60907813,90501309,3286998549,1016092578,2535922412,2839152426,457141659,509813237,4120667899,652014361,1966332200,2975202805,55981186,2327461051,676427537,3255491064,2882294119,3433927263,1307055953,942726286,933058658,2468411793,3933900994,4215176142,1361170020,2001714738,2830558078,3274259782,1222529897,1679025792,2729314320,3714953764,1770335741,151462246,3013232138,1682292957,1483529935,471910574,1539241949,458788160,3436315007,1807016891,3718408830,978976581,1043663428,3165965781,1927990952,4200891579,2372276910,3208408903,3533431907,1412390302,2931980059,4132332400,1947078029,3881505623,4168226417,2941484381,1077988104,1320477388,886195818,18198404,3786409e3,2509781533,112762804,3463356488,1866414978,891333506,18488651,661792760,1628790961,3885187036,3141171499,876946877,2693282273,1372485963,791857591,2686433993,3759982718,3167212022,3472953795,2716379847,445679433,3561995674,3504004811,3574258232,54117162,3331405415,2381918588,3769707343,4154350007,1140177722,4074052095,668550556,3214352940,367459370,261225585,2610173221,4209349473,3468074219,3265815641,314222801,3066103646,3808782860,282218597,3406013506,3773591054,379116347,1285071038,846784868,2669647154,3771962079,3550491691,2305946142,453669953,1268987020,3317592352,3279303384,3744833421,2610507566,3859509063,266596637,3847019092,517658769,3462560207,3443424879,370717030,4247526661,2224018117,4143653529,4112773975,2788324899,2477274417,1456262402,2901442914,1517677493,1846949527,2295493580,3734397586,2176403920,1280348187,1908823572,3871786941,846861322,1172426758,3287448474,3383383037,1655181056,3139813346,901632758,1897031941,2986607138,3066810236,3447102507,1393639104,373351379,950779232,625454576,3124240540,4148612726,2007998917,544563296,2244738638,2330496472,2058025392,1291430526,424198748,50039436,29584100,3605783033,2429876329,2791104160,1057563949,3255363231,3075367218,3463963227,1469046755,985887462])],this.P=new Uint32Array([608135816,2242054355,320440878,57701188,2752067618,698298832,137296536,3964562569,1160258022,953160567,3193202383,887688300,3232508343,3380367581,1065670069,3041331479,2450970073,2306472731])};function ji(n,t,e){return(n[0][t[e+3]]+n[1][t[e+2]]^n[2][t[e+1]])+n[3][t[e]]}ir.prototype.encipher=function(n,t){t===void 0&&(t=new Uint8Array(n.buffer),n.byteOffset!==0&&(t=t.subarray(n.byteOffset))),n[0]^=this.P[0];for(var e=1;e<16;e+=2)n[1]^=ji(this.S,t,0)^this.P[e],n[0]^=ji(this.S,t,4)^this.P[e+1];var r=n[0];n[0]=n[1]^this.P[17],n[1]=r};ir.prototype.decipher=function(n){var t=new Uint8Array(n.buffer);n.byteOffset!==0&&(t=t.subarray(n.byteOffset)),n[0]^=this.P[17];for(var e=16;e>0;e-=2)n[1]^=ji(this.S,t,0)^this.P[e],n[0]^=ji(this.S,t,4)^this.P[e-1];var r=n[0];n[0]=n[1]^this.P[0],n[1]=r};function rr(n,t){var e,r=0;for(e=0;e<4;e++,Rn++)Rn>=t&&(Rn=0),r=r<<8|n[Rn];return r}ir.prototype.expand0state=function(n,t){var e=new Uint32Array(2),r,s,i=new Uint8Array(e.buffer);for(r=0,Rn=0;r<18;r++)this.P[r]^=rr(n,t);for(Rn=0,r=0;r<18;r+=2)this.encipher(e,i),this.P[r]=e[0],this.P[r+1]=e[1];for(r=0;r<4;r++)for(s=0;s<256;s+=2)this.encipher(e,i),this.S[r][s]=e[0],this.S[r][s+1]=e[1]};ir.prototype.expandstate=function(n,t,e,r){var s=new Uint32Array(2),i,o;for(i=0,Rn=0;i<18;i++)this.P[i]^=rr(e,r);for(i=0,Rn=0;i<18;i+=2)s[0]^=rr(n,t),s[1]^=rr(n,t),this.encipher(s),this.P[i]=s[0],this.P[i+1]=s[1];for(i=0;i<4;i++)for(o=0;o<256;o+=2)s[0]^=rr(n,t),s[1]^=rr(n,t),this.encipher(s),this.S[i][o]=s[0],this.S[i][o+1]=s[1];Rn=0};ir.prototype.enc=function(n,t){for(var e=0;e<t;e++)this.encipher(n.subarray(e*2))};ir.prototype.dec=function(n,t){for(var e=0;e<t;e++)this.decipher(n.subarray(e*2))};var zi=8,ao=32;function co(n,t,e){var r=new ir,s=new Uint32Array(zi),i,o=new Uint8Array([79,120,121,99,104,114,111,109,97,116,105,99,66,108,111,119,102,105,115,104,83,119,97,116,68,121,110,97,109,105,116,101]);for(r.expandstate(t,64,n,64),i=0;i<64;i++)r.expand0state(t,64),r.expand0state(n,64);for(i=0;i<zi;i++)s[i]=rr(o,o.byteLength);for(i=0;i<64;i++)r.enc(s,s.byteLength/8);for(i=0;i<zi;i++)e[4*i+3]=s[i]>>>24,e[4*i+2]=s[i]>>>16,e[4*i+1]=s[i]>>>8,e[4*i+0]=s[i]}function ep(n,t,e,r,s,i,o){var a=new Uint8Array(64),c=new Uint8Array(64),f=new Uint8Array(ao),l=new Uint8Array(ao),u=new Uint8Array(r+4),h,g,y,_,b,C,L=i;if(o<1||t===0||r===0||i===0||i>f.byteLength*f.byteLength||r>1<<20)return-1;for(_=Math.floor((i+f.byteLength-1)/f.byteLength),y=Math.floor((i+_-1)/_),h=0;h<r;h++)u[h]=e[h];for(oo(a,n,t),C=1;i>0;C++){for(u[r+0]=C>>>24,u[r+1]=C>>>16,u[r+2]=C>>>8,u[r+3]=C,oo(c,u,r+4),co(a,c,l),h=f.byteLength;h--;)f[h]=l[h];for(h=1;h<o;h++)for(oo(c,l,l.byteLength),co(a,c,l),g=0;g<f.byteLength;g++)f[g]^=l[g];for(y=Math.min(y,i),h=0;h<y&&(b=h*_+(C-1),!(b>=L));h++)s[b]=f[h];i-=h}return 0}Pc.exports={BLOCKS:zi,HASHSIZE:ao,hash:co,pbkdf:ep}});var Pn=at((lE,Ji)=>{"use strict";var Nn=require("crypto"),Cr;try{Cr=require("cpu-features")()}catch{}var{bindingAvailable:Tc,CIPHER_INFO:tp,MAC_INFO:np}=Qn(),Lc=(()=>{if(typeof Nn.sign=="function"&&typeof Nn.verify=="function"){let n=`-----BEGIN PRIVATE KEY-----\r
|
|
2
2
|
MC4CAQAwBQYDK2VwBCIEIHKj+sVa9WcD/q2DJUJaf43Kptc8xYuUQA4bOFj9vC8T\r
|
|
3
|
-
-----END PRIVATE KEY-----`,t=Buffer.from("a"),e,r;try{e=Tn.sign(null,t,n),r=Tn.verify(null,t,n,e)}catch{}return Buffer.isBuffer(e)&&e.length===64&&r===!0}return!1})(),Au=typeof Tn.diffieHellman=="function"&&typeof Tn.generateKeyPairSync=="function"&&typeof Tn.createPublicKey=="function",ps=["ecdh-sha2-nistp256","ecdh-sha2-nistp384","ecdh-sha2-nistp521","diffie-hellman-group-exchange-sha256","diffie-hellman-group14-sha256","diffie-hellman-group15-sha512","diffie-hellman-group16-sha512","diffie-hellman-group17-sha512","diffie-hellman-group18-sha512"];Au&&(ps.unshift("curve25519-sha256"),ps.unshift("curve25519-sha256@libssh.org"));var mg=ps.concat(["diffie-hellman-group-exchange-sha1","diffie-hellman-group14-sha1","diffie-hellman-group1-sha1"]),Po=["ecdsa-sha2-nistp256","ecdsa-sha2-nistp384","ecdsa-sha2-nistp521","rsa-sha2-512","rsa-sha2-256","ssh-rsa"];mu&&Po.unshift("ssh-ed25519");var Ag=Po.concat(["ssh-dss"]),Eu=(()=>{let n=Tn.getCiphers();return t=>n.includes(pg[t].sslName)})(),qn=["aes128-gcm@openssh.com","aes256-gcm@openssh.com","aes128-ctr","aes192-ctr","aes256-ctr"];Lr&&Lr.flags&&!Lr.flags.aes?gu?qn.unshift("chacha20-poly1305@openssh.com"):qn.push("chacha20-poly1305@openssh.com"):gu&&Lr&&Lr.arch==="x86"?qn.splice(4,0,"chacha20-poly1305@openssh.com"):qn.push("chacha20-poly1305@openssh.com");qn=qn.filter(Eu);var Eg=qn.concat(["aes256-cbc","aes192-cbc","aes128-cbc","blowfish-cbc","3des-cbc","aes128-gcm","aes256-gcm","arcfour256","arcfour128","cast128-cbc","arcfour"].filter(Eu)),_u=(()=>{let n=Tn.getHashes();return t=>n.includes(gg[t].sslName)})(),yu=["hmac-sha2-256-etm@openssh.com","hmac-sha2-512-etm@openssh.com","hmac-sha1-etm@openssh.com","hmac-sha2-256","hmac-sha2-512","hmac-sha1"].filter(_u),_g=yu.concat(["hmac-md5","hmac-sha2-256-96","hmac-sha2-512-96","hmac-ripemd160","hmac-sha1-96","hmac-md5-96"].filter(_u)),bu=["none","zlib@openssh.com","zlib"],yg=bu.concat([]),Tr={BAD_DHGEX:1,OLD_EXIT:2,DYN_RPORT_BUG:4,BUG_DHGEX_LARGE:8,IMPLY_RSA_SHA2_SIGALGS:16};gs.exports={MESSAGE:{DISCONNECT:1,IGNORE:2,UNIMPLEMENTED:3,DEBUG:4,SERVICE_REQUEST:5,SERVICE_ACCEPT:6,EXT_INFO:7,KEXINIT:20,NEWKEYS:21,KEXDH_INIT:30,KEXDH_REPLY:31,KEXDH_GEX_GROUP:31,KEXDH_GEX_INIT:32,KEXDH_GEX_REPLY:33,KEXDH_GEX_REQUEST:34,KEXECDH_INIT:30,KEXECDH_REPLY:31,USERAUTH_REQUEST:50,USERAUTH_FAILURE:51,USERAUTH_SUCCESS:52,USERAUTH_BANNER:53,USERAUTH_PASSWD_CHANGEREQ:60,USERAUTH_PK_OK:60,USERAUTH_INFO_REQUEST:60,USERAUTH_INFO_RESPONSE:61,GLOBAL_REQUEST:80,REQUEST_SUCCESS:81,REQUEST_FAILURE:82,CHANNEL_OPEN:90,CHANNEL_OPEN_CONFIRMATION:91,CHANNEL_OPEN_FAILURE:92,CHANNEL_WINDOW_ADJUST:93,CHANNEL_DATA:94,CHANNEL_EXTENDED_DATA:95,CHANNEL_EOF:96,CHANNEL_CLOSE:97,CHANNEL_REQUEST:98,CHANNEL_SUCCESS:99,CHANNEL_FAILURE:100},DISCONNECT_REASON:{HOST_NOT_ALLOWED_TO_CONNECT:1,PROTOCOL_ERROR:2,KEY_EXCHANGE_FAILED:3,RESERVED:4,MAC_ERROR:5,COMPRESSION_ERROR:6,SERVICE_NOT_AVAILABLE:7,PROTOCOL_VERSION_NOT_SUPPORTED:8,HOST_KEY_NOT_VERIFIABLE:9,CONNECTION_LOST:10,BY_APPLICATION:11,TOO_MANY_CONNECTIONS:12,AUTH_CANCELED_BY_USER:13,NO_MORE_AUTH_METHODS_AVAILABLE:14,ILLEGAL_USER_NAME:15},DISCONNECT_REASON_STR:void 0,CHANNEL_OPEN_FAILURE:{ADMINISTRATIVELY_PROHIBITED:1,CONNECT_FAILED:2,UNKNOWN_CHANNEL_TYPE:3,RESOURCE_SHORTAGE:4},TERMINAL_MODE:{TTY_OP_END:0,VINTR:1,VQUIT:2,VERASE:3,VKILL:4,VEOF:5,VEOL:6,VEOL2:7,VSTART:8,VSTOP:9,VSUSP:10,VDSUSP:11,VREPRINT:12,VWERASE:13,VLNEXT:14,VFLUSH:15,VSWTCH:16,VSTATUS:17,VDISCARD:18,IGNPAR:30,PARMRK:31,INPCK:32,ISTRIP:33,INLCR:34,IGNCR:35,ICRNL:36,IUCLC:37,IXON:38,IXANY:39,IXOFF:40,IMAXBEL:41,ISIG:50,ICANON:51,XCASE:52,ECHO:53,ECHOE:54,ECHOK:55,ECHONL:56,NOFLSH:57,TOSTOP:58,IEXTEN:59,ECHOCTL:60,ECHOKE:61,PENDIN:62,OPOST:70,OLCUC:71,ONLCR:72,OCRNL:73,ONOCR:74,ONLRET:75,CS7:90,CS8:91,PARENB:92,PARODD:93,TTY_OP_ISPEED:128,TTY_OP_OSPEED:129},CHANNEL_EXTENDED_DATATYPE:{STDERR:1},SIGNALS:["ABRT","ALRM","FPE","HUP","ILL","INT","QUIT","SEGV","TERM","USR1","USR2","KILL","PIPE"].reduce((n,t)=>({...n,[t]:1}),{}),COMPAT:Tr,COMPAT_CHECKS:[["Cisco-1.25",Tr.BAD_DHGEX],[/^Cisco-1[.]/,Tr.BUG_DHGEX_LARGE],[/^[0-9.]+$/,Tr.OLD_EXIT],[/^OpenSSH_5[.][0-9]+/,Tr.DYN_RPORT_BUG],[/^OpenSSH_7[.]4/,Tr.IMPLY_RSA_SHA2_SIGALGS]],DEFAULT_KEX:ps,SUPPORTED_KEX:mg,DEFAULT_SERVER_HOST_KEY:Po,SUPPORTED_SERVER_HOST_KEY:Ag,DEFAULT_CIPHER:qn,SUPPORTED_CIPHER:Eg,DEFAULT_MAC:yu,SUPPORTED_MAC:_g,DEFAULT_COMPRESSION:bu,SUPPORTED_COMPRESSION:yg,curve25519Supported:Au,eddsaSupported:mu};gs.exports.DISCONNECT_REASON_BY_VALUE=Array.from(Object.entries(gs.exports.DISCONNECT_REASON)).reduce((n,[t,e])=>({...n,[e]:t}),{})});var hn=at((Dx,Iu)=>{"use strict";var ln=li().Ber,ms,wu=Buffer[Symbol.species],bg=Object.getPrototypeOf(Uint8Array.prototype).fill;function xu(n,t){return n[t++]*16777216+n[t++]*65536+n[t++]*256+n[t]}function ui(n,t,e,r,s){s||(s=0),r>n.length&&(r=n.length);let i=r-e,o=t.length-s;return i>o&&(i=o),t.set(new Uint8Array(n.buffer,n.byteOffset+e,i),s),i}function di(n,t,e){return e===void 0&&(e=n.length),new wu(n.buffer,n.byteOffset+t,e-t)}function Lo(){let n=0,t,e={init:(r,s)=>{t=r,n=typeof s=="number"?s:0},pos:()=>n,length:()=>t?t.length:0,avail:()=>t&&n<t.length?t.length-n:0,clear:()=>{t=void 0},readUInt32BE:()=>{if(!(!t||n+3>=t.length))return t[n++]*16777216+t[n++]*65536+t[n++]*256+t[n++]},readUInt64BE:r=>{if(!(!t||n+7>=t.length))switch(r){case"always":return BigInt(`0x${t.hexSlice(n,n+=8)}`);case"maybe":if(t[n]>31)return BigInt(`0x${t.hexSlice(n,n+=8)}`);default:return t[n++]*72057594037927940+t[n++]*281474976710656+t[n++]*1099511627776+t[n++]*4294967296+t[n++]*16777216+t[n++]*65536+t[n++]*256+t[n++]}},skip:r=>{t&&r>0&&(n+=r)},skipString:()=>{let r=e.readUInt32BE();if(r!==void 0)return n+=r,n<=t.length?r:void 0},readByte:()=>{if(t&&n<t.length)return t[n++]},readBool:()=>{if(t&&n<t.length)return!!t[n++]},readList:()=>{let r=e.readString(!0);if(r!==void 0)return r?r.split(","):[]},readString:(r,s)=>{typeof r=="number"&&(s=r,r=void 0);let i=e.readUInt32BE();if(i!==void 0&&!(t.length-n<i||typeof s=="number"&&i>s))return r?Buffer.isBuffer(r)?ui(t,r,n,n+=i):t.utf8Slice(n,n+=i):di(t,n,n+=i)},readRaw:r=>{if(t){if(typeof r!="number")return di(t,n,n+=t.length-n);if(t.length-n>=r)return di(t,n,n+=r)}}};return e}function Su(n,t,e){let r=new Error(n);return typeof t=="boolean"?(e=t,r.level="protocol"):r.level=t||"protocol",r.fatal=!!e,r}function To(n,t,e){return n[e++]=t>>>24,n[e++]=t>>>16,n[e++]=t>>>8,n[e++]=t,e}var As=Lo();Iu.exports={bufferCopy:ui,bufferSlice:di,FastBuffer:wu,bufferFill:(n,t,e,r)=>bg.call(n,t,e,r),makeError:Su,doFatalError:(n,t,e,r)=>{let s;return ms===void 0&&({DISCONNECT_REASON:ms}=Ln()),t instanceof Error?(s=t,typeof e!="number"?r=ms.PROTOCOL_ERROR:r=e):s=Su(t,e,!0),typeof r!="number"&&(r=ms.PROTOCOL_ERROR),n.disconnect(r),n._destruct(),n._onError(s),1/0},readUInt32BE:xu,writeUInt32BE:To,writeUInt32LE:(n,t,e)=>(n[e++]=t,n[e++]=t>>>8,n[e++]=t>>>16,n[e++]=t>>>24,e),makeBufferParser:Lo,bufferParser:Lo(),readString:(n,t,e,r)=>{typeof e=="number"&&(r=e,e=void 0),t===void 0&&(t=0);let s=n.length-t;if(t<0||t>=n.length||s<4)return;let i=xu(n,t);if(s<4+i||typeof r=="number"&&i>r)return;t+=4;let o=t+i;return n._pos=o,e?Buffer.isBuffer(e)?ui(n,e,t,o):n.utf8Slice(t,o):di(n,t,o)},sigSSHToASN1:(n,t)=>{switch(t){case"ssh-dss":{if(n.length>40)return n;let e=new ln.Writer;e.startSequence();let r=n.slice(0,20),s=n.slice(20);if(r[0]&128){let i=Buffer.allocUnsafe(21);i[0]=0,r.copy(i,1),r=i}else r[0]===0&&!(r[1]&128)&&(r=r.slice(1));if(s[0]&128){let i=Buffer.allocUnsafe(21);i[0]=0,s.copy(i,1),s=i}else s[0]===0&&!(s[1]&128)&&(s=s.slice(1));return e.writeBuffer(r,ln.Integer),e.writeBuffer(s,ln.Integer),e.endSequence(),e.buffer}case"ecdsa-sha2-nistp256":case"ecdsa-sha2-nistp384":case"ecdsa-sha2-nistp521":{As.init(n,0);let e=As.readString(),r=As.readString();if(As.clear(),e===void 0||r===void 0)return;let s=new ln.Writer;return s.startSequence(),s.writeBuffer(e,ln.Integer),s.writeBuffer(r,ln.Integer),s.endSequence(),s.buffer}default:return n}},convertSignature:(n,t)=>{switch(t){case"ssh-dss":{if(n.length<=40)return n;let e=new ln.Reader(n);e.readSequence();let r=e.readString(ln.Integer,!0),s=e.readString(ln.Integer,!0),i=0,o=0;if(r.length<20){let c=Buffer.allocUnsafe(20);c.set(r,1),r=c,r[0]=0}if(s.length<20){let c=Buffer.allocUnsafe(20);c.set(s,1),s=c,s[0]=0}r.length>20&&r[0]===0&&(i=1),s.length>20&&s[0]===0&&(o=1);let a=Buffer.allocUnsafe(r.length-i+(s.length-o));return ui(r,a,i,r.length,0),ui(s,a,o,s.length,r.length-i),a}case"ecdsa-sha2-nistp256":case"ecdsa-sha2-nistp384":case"ecdsa-sha2-nistp521":{if(n[0]===0)return n;let e=new ln.Reader(n);e.readSequence();let r=e.readString(ln.Integer,!0),s=e.readString(ln.Integer,!0);if(r===null||s===null)return;let i=Buffer.allocUnsafe(4+r.length+4+s.length);return To(i,r.length,0),i.set(r,4),To(i,s.length,4+r.length),i.set(s,8+r.length),i}}return n},sendPacket:(n,t,e)=>!e&&n._kexinit!==void 0?(n._queue===void 0&&(n._queue=[]),n._queue.push(t),n._debug&&n._debug("Outbound: ... packet queued"),!1):(n._cipher.encrypt(t),!0)}});var Cu=at((Es,Do)=>{var Uo=(function(){var n=typeof document<"u"&&document.currentScript?document.currentScript.src:void 0;return typeof __filename<"u"&&(n=n||__filename),(function(t){t=t||{};var e;e||(e=typeof t<"u"?t:{});var r,s;e.ready=new Promise(function(z,ue){r=z,s=ue});var i={},o;for(o in e)e.hasOwnProperty(o)&&(i[o]=e[o]);var a=typeof window=="object",c=typeof importScripts=="function",f=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string",l="",u,h,g,y,_;f?(l=c?require("path").dirname(l)+"/":__dirname+"/",u=function(z,ue){var xe=kn(z);return xe?ue?xe:xe.toString():(y||(y=require("fs")),_||(_=require("path")),z=_.normalize(z),y.readFileSync(z,ue?null:"utf8"))},g=function(z){return z=u(z,!0),z.buffer||(z=new Uint8Array(z)),K(z.buffer),z},h=function(z,ue,xe){var Pe=kn(z);Pe&&ue(Pe),y||(y=require("fs")),_||(_=require("path")),z=_.normalize(z),y.readFile(z,function(je,Nt){je?xe(je):ue(Nt.buffer)})},1<process.argv.length&&process.argv[1].replace(/\\/g,"/"),process.argv.slice(2),e.inspect=function(){return"[Emscripten Module object]"}):(a||c)&&(c?l=self.location.href:typeof document<"u"&&document.currentScript&&(l=document.currentScript.src),n&&(l=n),l.indexOf("blob:")!==0?l=l.substr(0,l.lastIndexOf("/")+1):l="",u=function(z){try{var ue=new XMLHttpRequest;return ue.open("GET",z,!1),ue.send(null),ue.responseText}catch(je){if(z=kn(z)){ue=[];for(var xe=0;xe<z.length;xe++){var Pe=z[xe];255<Pe&&(pr&&K(!1,"Character code "+Pe+" ("+String.fromCharCode(Pe)+") at offset "+xe+" not in 0x00-0xFF."),Pe&=255),ue.push(String.fromCharCode(Pe))}return ue.join("")}throw je}},c&&(g=function(z){try{var ue=new XMLHttpRequest;return ue.open("GET",z,!1),ue.responseType="arraybuffer",ue.send(null),new Uint8Array(ue.response)}catch(xe){if(z=kn(z))return z;throw xe}}),h=function(z,ue,xe){var Pe=new XMLHttpRequest;Pe.open("GET",z,!0),Pe.responseType="arraybuffer",Pe.onload=function(){if(Pe.status==200||Pe.status==0&&Pe.response)ue(Pe.response);else{var je=kn(z);je?ue(je.buffer):xe()}},Pe.onerror=xe,Pe.send(null)}),e.print||console.log.bind(console);var b=e.printErr||console.warn.bind(console);for(o in i)i.hasOwnProperty(o)&&(e[o]=i[o]);i=null;var C;e.wasmBinary&&(C=e.wasmBinary);var L=e.noExitRuntime||!0;typeof WebAssembly!="object"&&H("no native wasm support detected");var F,k=!1;function K(z,ue){z||H("Assertion failed: "+ue)}function ee(z){var ue=e["_"+z];return K(ue,"Cannot call unknown function "+z+", make sure it is exported"),ue}function O(z,ue,xe,Pe){var je={string:function(ot){var Ut=0;if(ot!=null&&ot!==0){var Tt=(ot.length<<2)+1;Ut=Xr(Tt);var bt=Ut,ut=U;if(0<Tt){Tt=bt+Tt-1;for(var an=0;an<ot.length;++an){var xt=ot.charCodeAt(an);if(55296<=xt&&57343>=xt){var tr=ot.charCodeAt(++an);xt=65536+((xt&1023)<<10)|tr&1023}if(127>=xt){if(bt>=Tt)break;ut[bt++]=xt}else{if(2047>=xt){if(bt+1>=Tt)break;ut[bt++]=192|xt>>6}else{if(65535>=xt){if(bt+2>=Tt)break;ut[bt++]=224|xt>>12}else{if(bt+3>=Tt)break;ut[bt++]=240|xt>>18,ut[bt++]=128|xt>>12&63}ut[bt++]=128|xt>>6&63}ut[bt++]=128|xt&63}}ut[bt]=0}}return Ut},array:function(ot){var Ut=Xr(ot.length);return I.set(ot,Ut),Ut}},Nt=ee(z),En=[];if(z=0,Pe)for(var tn=0;tn<Pe.length;tn++){var _r=je[xe[tn]];_r?(z===0&&(z=jr()),En[tn]=_r(Pe[tn])):En[tn]=Pe[tn]}return xe=Nt.apply(null,En),xe=(function(ot){if(ue==="string")if(ot){for(var Ut=U,Tt=ot+NaN,bt=ot;Ut[bt]&&!(bt>=Tt);)++bt;if(16<bt-ot&&Ut.subarray&&x)ot=x.decode(Ut.subarray(ot,bt));else{for(Tt="";ot<bt;){var ut=Ut[ot++];if(ut&128){var an=Ut[ot++]&63;if((ut&224)==192)Tt+=String.fromCharCode((ut&31)<<6|an);else{var xt=Ut[ot++]&63;ut=(ut&240)==224?(ut&15)<<12|an<<6|xt:(ut&7)<<18|an<<12|xt<<6|Ut[ot++]&63,65536>ut?Tt+=String.fromCharCode(ut):(ut-=65536,Tt+=String.fromCharCode(55296|ut>>10,56320|ut&1023))}}else Tt+=String.fromCharCode(ut)}ot=Tt}}else ot="";else ot=ue==="boolean"?!!ot:ot;return ot})(xe),z!==0&&Mi(z),xe}var x=typeof TextDecoder<"u"?new TextDecoder("utf8"):void 0,w,I,U;function R(){var z=F.buffer;w=z,e.HEAP8=I=new Int8Array(z),e.HEAP16=new Int16Array(z),e.HEAP32=new Int32Array(z),e.HEAPU8=U=new Uint8Array(z),e.HEAPU16=new Uint16Array(z),e.HEAPU32=new Uint32Array(z),e.HEAPF32=new Float32Array(z),e.HEAPF64=new Float64Array(z)}var re,G=[],Y=[],te=[];function ce(){var z=e.preRun.shift();G.unshift(z)}var D=0,v=null,N=null;e.preloadedImages={},e.preloadedAudios={};function H(z){throw e.onAbort&&e.onAbort(z),b(z),k=!0,z=new WebAssembly.RuntimeError("abort("+z+"). Build with -s ASSERTIONS=1 for more info."),s(z),z}var X="data:application/octet-stream;base64,",fe;if(fe="data:application/octet-stream;base64,AGFzbQEAAAABIAZgAX8Bf2ADf39/AGABfwBgAABgAAF/YAZ/f39/f38AAgcBAWEBYQAAAwsKAAEDAQAAAgQFAgQFAXABAQEFBwEBgAKAgAIGCQF/AUGAjMACCwclCQFiAgABYwADAWQACQFlAAgBZgAHAWcABgFoAAUBaQAKAWoBAAqGTQpPAQJ/QYAIKAIAIgEgAEEDakF8cSICaiEAAkAgAkEAIAAgAU0bDQAgAD8AQRB0SwRAIAAQAEUNAQtBgAggADYCACABDwtBhAhBMDYCAEF/C4wFAg5+Cn8gACgCJCEUIAAoAiAhFSAAKAIcIREgACgCGCESIAAoAhQhEyACQRBPBEAgAC0ATEVBGHQhFyAAKAIEIhZBBWytIQ8gACgCCCIYQQVsrSENIAAoAgwiGUEFbK0hCyAAKAIQIhpBBWytIQkgADUCACEIIBqtIRAgGa0hDiAYrSEMIBatIQoDQCASIAEtAAMiEiABLQAEQQh0ciABLQAFQRB0ciABLQAGIhZBGHRyQQJ2Qf///x9xaq0iAyAOfiABLwAAIAEtAAJBEHRyIBNqIBJBGHRBgICAGHFqrSIEIBB+fCARIAEtAAdBCHQgFnIgAS0ACEEQdHIgAS0ACSIRQRh0ckEEdkH///8fcWqtIgUgDH58IAEtAApBCHQgEXIgAS0AC0EQdHIgAS0ADEEYdHJBBnYgFWqtIgYgCn58IBQgF2ogAS8ADSABLQAPQRB0cmqtIgcgCH58IAMgDH4gBCAOfnwgBSAKfnwgBiAIfnwgByAJfnwgAyAKfiAEIAx+fCAFIAh+fCAGIAl+fCAHIAt+fCADIAh+IAQgCn58IAUgCX58IAYgC358IAcgDX58IAMgCX4gBCAIfnwgBSALfnwgBiANfnwgByAPfnwiA0IaiEL/////D4N8IgRCGohC/////w+DfCIFQhqIQv////8Pg3wiBkIaiEL/////D4N8IgdCGoinQQVsIAOnQf///x9xaiITQRp2IASnQf///x9xaiESIAWnQf///x9xIREgBqdB////H3EhFSAHp0H///8fcSEUIBNB////H3EhEyABQRBqIQEgAkEQayICQQ9LDQALCyAAIBQ2AiQgACAVNgIgIAAgETYCHCAAIBI2AhggACATNgIUCwMAAQu2BAEGfwJAIAAoAjgiBARAIABBPGohBQJAIAJBECAEayIDIAIgA0kbIgZFDQAgBkEDcSEHAkAgBkEBa0EDSQRAQQAhAwwBCyAGQXxxIQhBACEDA0AgBSADIARqaiABIANqLQAAOgAAIAUgA0EBciIEIAAoAjhqaiABIARqLQAAOgAAIAUgA0ECciIEIAAoAjhqaiABIARqLQAAOgAAIAUgA0EDciIEIAAoAjhqaiABIARqLQAAOgAAIANBBGohAyAAKAI4IQQgCEEEayIIDQALCyAHRQ0AA0AgBSADIARqaiABIANqLQAAOgAAIANBAWohAyAAKAI4IQQgB0EBayIHDQALCyAAIAQgBmoiAzYCOCADQRBJDQEgACAFQRAQAiAAQQA2AjggAiAGayECIAEgBmohAQsgAkEQTwRAIAAgASACQXBxIgMQAiACQQ9xIQIgASADaiEBCyACRQ0AIAJBA3EhBCAAQTxqIQVBACEDIAJBAWtBA08EQCACQXxxIQcDQCAFIAAoAjggA2pqIAEgA2otAAA6AAAgBSADQQFyIgYgACgCOGpqIAEgBmotAAA6AAAgBSADQQJyIgYgACgCOGpqIAEgBmotAAA6AAAgBSADQQNyIgYgACgCOGpqIAEgBmotAAA6AAAgA0EEaiEDIAdBBGsiBw0ACwsgBARAA0AgBSAAKAI4IANqaiABIANqLQAAOgAAIANBAWohAyAEQQFrIgQNAAsLIAAgACgCOCACajYCOAsLoS0BDH8jAEEQayIMJAACQAJAAkACQAJAAkACQAJAAkACQAJAAkAgAEH0AU0EQEGICCgCACIFQRAgAEELakF4cSAAQQtJGyIIQQN2IgJ2IgFBA3EEQCABQX9zQQFxIAJqIgNBA3QiAUG4CGooAgAiBEEIaiEAAkAgBCgCCCICIAFBsAhqIgFGBEBBiAggBUF+IAN3cTYCAAwBCyACIAE2AgwgASACNgIICyAEIANBA3QiAUEDcjYCBCABIARqIgEgASgCBEEBcjYCBAwNCyAIQZAIKAIAIgpNDQEgAQRAAkBBAiACdCIAQQAgAGtyIAEgAnRxIgBBACAAa3FBAWsiACAAQQx2QRBxIgJ2IgFBBXZBCHEiACACciABIAB2IgFBAnZBBHEiAHIgASAAdiIBQQF2QQJxIgByIAEgAHYiAUEBdkEBcSIAciABIAB2aiIDQQN0IgBBuAhqKAIAIgQoAggiASAAQbAIaiIARgRAQYgIIAVBfiADd3EiBTYCAAwBCyABIAA2AgwgACABNgIICyAEQQhqIQAgBCAIQQNyNgIEIAQgCGoiAiADQQN0IgEgCGsiA0EBcjYCBCABIARqIAM2AgAgCgRAIApBA3YiAUEDdEGwCGohB0GcCCgCACEEAn8gBUEBIAF0IgFxRQRAQYgIIAEgBXI2AgAgBwwBCyAHKAIICyEBIAcgBDYCCCABIAQ2AgwgBCAHNgIMIAQgATYCCAtBnAggAjYCAEGQCCADNgIADA0LQYwIKAIAIgZFDQEgBkEAIAZrcUEBayIAIABBDHZBEHEiAnYiAUEFdkEIcSIAIAJyIAEgAHYiAUECdkEEcSIAciABIAB2IgFBAXZBAnEiAHIgASAAdiIBQQF2QQFxIgByIAEgAHZqQQJ0QbgKaigCACIBKAIEQXhxIAhrIQMgASECA0ACQCACKAIQIgBFBEAgAigCFCIARQ0BCyAAKAIEQXhxIAhrIgIgAyACIANJIgIbIQMgACABIAIbIQEgACECDAELCyABIAhqIgkgAU0NAiABKAIYIQsgASABKAIMIgRHBEAgASgCCCIAQZgIKAIASRogACAENgIMIAQgADYCCAwMCyABQRRqIgIoAgAiAEUEQCABKAIQIgBFDQQgAUEQaiECCwNAIAIhByAAIgRBFGoiAigCACIADQAgBEEQaiECIAQoAhAiAA0ACyAHQQA2AgAMCwtBfyEIIABBv39LDQAgAEELaiIAQXhxIQhBjAgoAgAiCUUNAEEAIAhrIQMCQAJAAkACf0EAIAhBgAJJDQAaQR8gCEH///8HSw0AGiAAQQh2IgAgAEGA/j9qQRB2QQhxIgJ0IgAgAEGA4B9qQRB2QQRxIgF0IgAgAEGAgA9qQRB2QQJxIgB0QQ92IAEgAnIgAHJrIgBBAXQgCCAAQRVqdkEBcXJBHGoLIgVBAnRBuApqKAIAIgJFBEBBACEADAELQQAhACAIQQBBGSAFQQF2ayAFQR9GG3QhAQNAAkAgAigCBEF4cSAIayIHIANPDQAgAiEEIAciAw0AQQAhAyACIQAMAwsgACACKAIUIgcgByACIAFBHXZBBHFqKAIQIgJGGyAAIAcbIQAgAUEBdCEBIAINAAsLIAAgBHJFBEBBACEEQQIgBXQiAEEAIABrciAJcSIARQ0DIABBACAAa3FBAWsiACAAQQx2QRBxIgJ2IgFBBXZBCHEiACACciABIAB2IgFBAnZBBHEiAHIgASAAdiIBQQF2QQJxIgByIAEgAHYiAUEBdkEBcSIAciABIAB2akECdEG4CmooAgAhAAsgAEUNAQsDQCAAKAIEQXhxIAhrIgEgA0khAiABIAMgAhshAyAAIAQgAhshBCAAKAIQIgEEfyABBSAAKAIUCyIADQALCyAERQ0AIANBkAgoAgAgCGtPDQAgBCAIaiIGIARNDQEgBCgCGCEFIAQgBCgCDCIBRwRAIAQoAggiAEGYCCgCAEkaIAAgATYCDCABIAA2AggMCgsgBEEUaiICKAIAIgBFBEAgBCgCECIARQ0EIARBEGohAgsDQCACIQcgACIBQRRqIgIoAgAiAA0AIAFBEGohAiABKAIQIgANAAsgB0EANgIADAkLIAhBkAgoAgAiAk0EQEGcCCgCACEDAkAgAiAIayIBQRBPBEBBkAggATYCAEGcCCADIAhqIgA2AgAgACABQQFyNgIEIAIgA2ogATYCACADIAhBA3I2AgQMAQtBnAhBADYCAEGQCEEANgIAIAMgAkEDcjYCBCACIANqIgAgACgCBEEBcjYCBAsgA0EIaiEADAsLIAhBlAgoAgAiBkkEQEGUCCAGIAhrIgE2AgBBoAhBoAgoAgAiAiAIaiIANgIAIAAgAUEBcjYCBCACIAhBA3I2AgQgAkEIaiEADAsLQQAhACAIQS9qIgkCf0HgCygCAARAQegLKAIADAELQewLQn83AgBB5AtCgKCAgICABDcCAEHgCyAMQQxqQXBxQdiq1aoFczYCAEH0C0EANgIAQcQLQQA2AgBBgCALIgFqIgVBACABayIHcSICIAhNDQpBwAsoAgAiBARAQbgLKAIAIgMgAmoiASADTQ0LIAEgBEsNCwtBxAstAABBBHENBQJAAkBBoAgoAgAiAwRAQcgLIQADQCADIAAoAgAiAU8EQCABIAAoAgRqIANLDQMLIAAoAggiAA0ACwtBABABIgFBf0YNBiACIQVB5AsoAgAiA0EBayIAIAFxBEAgAiABayAAIAFqQQAgA2txaiEFCyAFIAhNDQYgBUH+////B0sNBkHACygCACIEBEBBuAsoAgAiAyAFaiIAIANNDQcgACAESw0HCyAFEAEiACABRw0BDAgLIAUgBmsgB3EiBUH+////B0sNBSAFEAEiASAAKAIAIAAoAgRqRg0EIAEhAAsCQCAAQX9GDQAgCEEwaiAFTQ0AQegLKAIAIgEgCSAFa2pBACABa3EiAUH+////B0sEQCAAIQEMCAsgARABQX9HBEAgASAFaiEFIAAhAQwIC0EAIAVrEAEaDAULIAAiAUF/Rw0GDAQLAAtBACEEDAcLQQAhAQwFCyABQX9HDQILQcQLQcQLKAIAQQRyNgIACyACQf7///8HSw0BIAIQASEBQQAQASEAIAFBf0YNASAAQX9GDQEgACABTQ0BIAAgAWsiBSAIQShqTQ0BC0G4C0G4CygCACAFaiIANgIAQbwLKAIAIABJBEBBvAsgADYCAAsCQAJAAkBBoAgoAgAiBwRAQcgLIQADQCABIAAoAgAiAyAAKAIEIgJqRg0CIAAoAggiAA0ACwwCC0GYCCgCACIAQQAgACABTRtFBEBBmAggATYCAAtBACEAQcwLIAU2AgBByAsgATYCAEGoCEF/NgIAQawIQeALKAIANgIAQdQLQQA2AgADQCAAQQN0IgNBuAhqIANBsAhqIgI2AgAgA0G8CGogAjYCACAAQQFqIgBBIEcNAAtBlAggBUEoayIDQXggAWtBB3FBACABQQhqQQdxGyIAayICNgIAQaAIIAAgAWoiADYCACAAIAJBAXI2AgQgASADakEoNgIEQaQIQfALKAIANgIADAILIAAtAAxBCHENACADIAdLDQAgASAHTQ0AIAAgAiAFajYCBEGgCCAHQXggB2tBB3FBACAHQQhqQQdxGyIAaiICNgIAQZQIQZQIKAIAIAVqIgEgAGsiADYCACACIABBAXI2AgQgASAHakEoNgIEQaQIQfALKAIANgIADAELQZgIKAIAIAFLBEBBmAggATYCAAsgASAFaiECQcgLIQACQAJAAkACQAJAAkADQCACIAAoAgBHBEAgACgCCCIADQEMAgsLIAAtAAxBCHFFDQELQcgLIQADQCAHIAAoAgAiAk8EQCACIAAoAgRqIgQgB0sNAwsgACgCCCEADAALAAsgACABNgIAIAAgACgCBCAFajYCBCABQXggAWtBB3FBACABQQhqQQdxG2oiCSAIQQNyNgIEIAJBeCACa0EHcUEAIAJBCGpBB3EbaiIFIAggCWoiBmshAiAFIAdGBEBBoAggBjYCAEGUCEGUCCgCACACaiIANgIAIAYgAEEBcjYCBAwDCyAFQZwIKAIARgRAQZwIIAY2AgBBkAhBkAgoAgAgAmoiADYCACAGIABBAXI2AgQgACAGaiAANgIADAMLIAUoAgQiAEEDcUEBRgRAIABBeHEhBwJAIABB/wFNBEAgBSgCCCIDIABBA3YiAEEDdEGwCGpGGiADIAUoAgwiAUYEQEGICEGICCgCAEF+IAB3cTYCAAwCCyADIAE2AgwgASADNgIIDAELIAUoAhghCAJAIAUgBSgCDCIBRwRAIAUoAggiACABNgIMIAEgADYCCAwBCwJAIAVBFGoiACgCACIDDQAgBUEQaiIAKAIAIgMNAEEAIQEMAQsDQCAAIQQgAyIBQRRqIgAoAgAiAw0AIAFBEGohACABKAIQIgMNAAsgBEEANgIACyAIRQ0AAkAgBSAFKAIcIgNBAnRBuApqIgAoAgBGBEAgACABNgIAIAENAUGMCEGMCCgCAEF+IAN3cTYCAAwCCyAIQRBBFCAIKAIQIAVGG2ogATYCACABRQ0BCyABIAg2AhggBSgCECIABEAgASAANgIQIAAgATYCGAsgBSgCFCIARQ0AIAEgADYCFCAAIAE2AhgLIAUgB2ohBSACIAdqIQILIAUgBSgCBEF+cTYCBCAGIAJBAXI2AgQgAiAGaiACNgIAIAJB/wFNBEAgAkEDdiIAQQN0QbAIaiECAn9BiAgoAgAiAUEBIAB0IgBxRQRAQYgIIAAgAXI2AgAgAgwBCyACKAIICyEAIAIgBjYCCCAAIAY2AgwgBiACNgIMIAYgADYCCAwDC0EfIQAgAkH///8HTQRAIAJBCHYiACAAQYD+P2pBEHZBCHEiA3QiACAAQYDgH2pBEHZBBHEiAXQiACAAQYCAD2pBEHZBAnEiAHRBD3YgASADciAAcmsiAEEBdCACIABBFWp2QQFxckEcaiEACyAGIAA2AhwgBkIANwIQIABBAnRBuApqIQQCQEGMCCgCACIDQQEgAHQiAXFFBEBBjAggASADcjYCACAEIAY2AgAgBiAENgIYDAELIAJBAEEZIABBAXZrIABBH0YbdCEAIAQoAgAhAQNAIAEiAygCBEF4cSACRg0DIABBHXYhASAAQQF0IQAgAyABQQRxaiIEKAIQIgENAAsgBCAGNgIQIAYgAzYCGAsgBiAGNgIMIAYgBjYCCAwCC0GUCCAFQShrIgNBeCABa0EHcUEAIAFBCGpBB3EbIgBrIgI2AgBBoAggACABaiIANgIAIAAgAkEBcjYCBCABIANqQSg2AgRBpAhB8AsoAgA2AgAgByAEQScgBGtBB3FBACAEQSdrQQdxG2pBL2siACAAIAdBEGpJGyICQRs2AgQgAkHQCykCADcCECACQcgLKQIANwIIQdALIAJBCGo2AgBBzAsgBTYCAEHICyABNgIAQdQLQQA2AgAgAkEYaiEAA0AgAEEHNgIEIABBCGohASAAQQRqIQAgASAESQ0ACyACIAdGDQMgAiACKAIEQX5xNgIEIAcgAiAHayIEQQFyNgIEIAIgBDYCACAEQf8BTQRAIARBA3YiAEEDdEGwCGohAgJ/QYgIKAIAIgFBASAAdCIAcUUEQEGICCAAIAFyNgIAIAIMAQsgAigCCAshACACIAc2AgggACAHNgIMIAcgAjYCDCAHIAA2AggMBAtBHyEAIAdCADcCECAEQf///wdNBEAgBEEIdiIAIABBgP4/akEQdkEIcSICdCIAIABBgOAfakEQdkEEcSIBdCIAIABBgIAPakEQdkECcSIAdEEPdiABIAJyIAByayIAQQF0IAQgAEEVanZBAXFyQRxqIQALIAcgADYCHCAAQQJ0QbgKaiEDAkBBjAgoAgAiAkEBIAB0IgFxRQRAQYwIIAEgAnI2AgAgAyAHNgIAIAcgAzYCGAwBCyAEQQBBGSAAQQF2ayAAQR9GG3QhACADKAIAIQEDQCABIgIoAgRBeHEgBEYNBCAAQR12IQEgAEEBdCEAIAIgAUEEcWoiAygCECIBDQALIAMgBzYCECAHIAI2AhgLIAcgBzYCDCAHIAc2AggMAwsgAygCCCIAIAY2AgwgAyAGNgIIIAZBADYCGCAGIAM2AgwgBiAANgIICyAJQQhqIQAMBQsgAigCCCIAIAc2AgwgAiAHNgIIIAdBADYCGCAHIAI2AgwgByAANgIIC0GUCCgCACIAIAhNDQBBlAggACAIayIBNgIAQaAIQaAIKAIAIgIgCGoiADYCACAAIAFBAXI2AgQgAiAIQQNyNgIEIAJBCGohAAwDC0GECEEwNgIAQQAhAAwCCwJAIAVFDQACQCAEKAIcIgJBAnRBuApqIgAoAgAgBEYEQCAAIAE2AgAgAQ0BQYwIIAlBfiACd3EiCTYCAAwCCyAFQRBBFCAFKAIQIARGG2ogATYCACABRQ0BCyABIAU2AhggBCgCECIABEAgASAANgIQIAAgATYCGAsgBCgCFCIARQ0AIAEgADYCFCAAIAE2AhgLAkAgA0EPTQRAIAQgAyAIaiIAQQNyNgIEIAAgBGoiACAAKAIEQQFyNgIEDAELIAQgCEEDcjYCBCAGIANBAXI2AgQgAyAGaiADNgIAIANB/wFNBEAgA0EDdiIAQQN0QbAIaiECAn9BiAgoAgAiAUEBIAB0IgBxRQRAQYgIIAAgAXI2AgAgAgwBCyACKAIICyEAIAIgBjYCCCAAIAY2AgwgBiACNgIMIAYgADYCCAwBC0EfIQAgA0H///8HTQRAIANBCHYiACAAQYD+P2pBEHZBCHEiAnQiACAAQYDgH2pBEHZBBHEiAXQiACAAQYCAD2pBEHZBAnEiAHRBD3YgASACciAAcmsiAEEBdCADIABBFWp2QQFxckEcaiEACyAGIAA2AhwgBkIANwIQIABBAnRBuApqIQICQAJAIAlBASAAdCIBcUUEQEGMCCABIAlyNgIAIAIgBjYCACAGIAI2AhgMAQsgA0EAQRkgAEEBdmsgAEEfRht0IQAgAigCACEIA0AgCCIBKAIEQXhxIANGDQIgAEEddiECIABBAXQhACABIAJBBHFqIgIoAhAiCA0ACyACIAY2AhAgBiABNgIYCyAGIAY2AgwgBiAGNgIIDAELIAEoAggiACAGNgIMIAEgBjYCCCAGQQA2AhggBiABNgIMIAYgADYCCAsgBEEIaiEADAELAkAgC0UNAAJAIAEoAhwiAkECdEG4CmoiACgCACABRgRAIAAgBDYCACAEDQFBjAggBkF+IAJ3cTYCAAwCCyALQRBBFCALKAIQIAFGG2ogBDYCACAERQ0BCyAEIAs2AhggASgCECIABEAgBCAANgIQIAAgBDYCGAsgASgCFCIARQ0AIAQgADYCFCAAIAQ2AhgLAkAgA0EPTQRAIAEgAyAIaiIAQQNyNgIEIAAgAWoiACAAKAIEQQFyNgIEDAELIAEgCEEDcjYCBCAJIANBAXI2AgQgAyAJaiADNgIAIAoEQCAKQQN2IgBBA3RBsAhqIQRBnAgoAgAhAgJ/QQEgAHQiACAFcUUEQEGICCAAIAVyNgIAIAQMAQsgBCgCCAshACAEIAI2AgggACACNgIMIAIgBDYCDCACIAA2AggLQZwIIAk2AgBBkAggAzYCAAsgAUEIaiEACyAMQRBqJAAgAAsQACMAIABrQXBxIgAkACAACwYAIAAkAAsEACMAC4AJAgh/BH4jAEGQAWsiBiQAIAYgBS0AA0EYdEGAgIAYcSAFLwAAIAUtAAJBEHRycjYCACAGIAUoAANBAnZBg/7/H3E2AgQgBiAFKAAGQQR2Qf+B/x9xNgIIIAYgBSgACUEGdkH//8AfcTYCDCAFLwANIQggBS0ADyEJIAZCADcCFCAGQgA3AhwgBkEANgIkIAYgCCAJQRB0QYCAPHFyNgIQIAYgBSgAEDYCKCAGIAUoABQ2AiwgBiAFKAAYNgIwIAUoABwhBSAGQQA6AEwgBkEANgI4IAYgBTYCNCAGIAEgAhAEIAQEQCAGIAMgBBAECyAGKAI4IgEEQCAGQTxqIgIgAWpBAToAACABQQFqQQ9NBEAgASAGakE9aiEEAkBBDyABayIDRQ0AIAMgBGoiAUEBa0EAOgAAIARBADoAACADQQNJDQAgAUECa0EAOgAAIARBADoAASABQQNrQQA6AAAgBEEAOgACIANBB0kNACABQQRrQQA6AAAgBEEAOgADIANBCUkNACAEQQAgBGtBA3EiAWoiBEEANgIAIAQgAyABa0F8cSIBaiIDQQRrQQA2AgAgAUEJSQ0AIARBADYCCCAEQQA2AgQgA0EIa0EANgIAIANBDGtBADYCACABQRlJDQAgBEEANgIYIARBADYCFCAEQQA2AhAgBEEANgIMIANBEGtBADYCACADQRRrQQA2AgAgA0EYa0EANgIAIANBHGtBADYCACABIARBBHFBGHIiAWsiA0EgSQ0AIAEgBGohAQNAIAFCADcDGCABQgA3AxAgAUIANwMIIAFCADcDACABQSBqIQEgA0EgayIDQR9LDQALCwsgBkEBOgBMIAYgAkEQEAILIAY1AjQhECAGNQIwIREgBjUCLCEOIAAgBjUCKCAGKAIkIAYoAiAgBigCHCAGKAIYIgNBGnZqIgJBGnZqIgFBGnZqIgtBgICAYHIgAUH///8fcSINIAJB////H3EiCCAGKAIUIAtBGnZBBWxqIgFB////H3EiCUEFaiIFQRp2IANB////H3EgAUEadmoiA2oiAUEadmoiAkEadmoiBEEadmoiDEEfdSIHIANxIAEgDEEfdkEBayIDQf///x9xIgpxciIBQRp0IAUgCnEgByAJcXJyrXwiDzwAACAAIA9CGIg8AAMgACAPQhCIPAACIAAgD0IIiDwAASAAIA4gByAIcSACIApxciICQRR0IAFBBnZyrXwgD0IgiHwiDjwABCAAIA5CGIg8AAcgACAOQhCIPAAGIAAgDkIIiDwABSAAIBEgByANcSAEIApxciIBQQ50IAJBDHZyrXwgDkIgiHwiDjwACCAAIA5CGIg8AAsgACAOQhCIPAAKIAAgDkIIiDwACSAAIBAgAyAMcSAHIAtxckEIdCABQRJ2cq18IA5CIIh8Ig48AAwgACAOQhiIPAAPIAAgDkIQiDwADiAAIA5CCIg8AA0gBkIANwIwIAZCADcCKCAGQgA3AiAgBkIANwIYIAZCADcCECAGQgA3AgggBkIANwIAIAZBkAFqJAALpwwBB38CQCAARQ0AIABBCGsiAyAAQQRrKAIAIgFBeHEiAGohBQJAIAFBAXENACABQQNxRQ0BIAMgAygCACIBayIDQZgIKAIASQ0BIAAgAWohACADQZwIKAIARwRAIAFB/wFNBEAgAygCCCICIAFBA3YiBEEDdEGwCGpGGiACIAMoAgwiAUYEQEGICEGICCgCAEF+IAR3cTYCAAwDCyACIAE2AgwgASACNgIIDAILIAMoAhghBgJAIAMgAygCDCIBRwRAIAMoAggiAiABNgIMIAEgAjYCCAwBCwJAIANBFGoiAigCACIEDQAgA0EQaiICKAIAIgQNAEEAIQEMAQsDQCACIQcgBCIBQRRqIgIoAgAiBA0AIAFBEGohAiABKAIQIgQNAAsgB0EANgIACyAGRQ0BAkAgAyADKAIcIgJBAnRBuApqIgQoAgBGBEAgBCABNgIAIAENAUGMCEGMCCgCAEF+IAJ3cTYCAAwDCyAGQRBBFCAGKAIQIANGG2ogATYCACABRQ0CCyABIAY2AhggAygCECICBEAgASACNgIQIAIgATYCGAsgAygCFCICRQ0BIAEgAjYCFCACIAE2AhgMAQsgBSgCBCIBQQNxQQNHDQBBkAggADYCACAFIAFBfnE2AgQgAyAAQQFyNgIEIAAgA2ogADYCAA8LIAMgBU8NACAFKAIEIgFBAXFFDQACQCABQQJxRQRAIAVBoAgoAgBGBEBBoAggAzYCAEGUCEGUCCgCACAAaiIANgIAIAMgAEEBcjYCBCADQZwIKAIARw0DQZAIQQA2AgBBnAhBADYCAA8LIAVBnAgoAgBGBEBBnAggAzYCAEGQCEGQCCgCACAAaiIANgIAIAMgAEEBcjYCBCAAIANqIAA2AgAPCyABQXhxIABqIQACQCABQf8BTQRAIAUoAggiAiABQQN2IgRBA3RBsAhqRhogAiAFKAIMIgFGBEBBiAhBiAgoAgBBfiAEd3E2AgAMAgsgAiABNgIMIAEgAjYCCAwBCyAFKAIYIQYCQCAFIAUoAgwiAUcEQCAFKAIIIgJBmAgoAgBJGiACIAE2AgwgASACNgIIDAELAkAgBUEUaiICKAIAIgQNACAFQRBqIgIoAgAiBA0AQQAhAQwBCwNAIAIhByAEIgFBFGoiAigCACIEDQAgAUEQaiECIAEoAhAiBA0ACyAHQQA2AgALIAZFDQACQCAFIAUoAhwiAkECdEG4CmoiBCgCAEYEQCAEIAE2AgAgAQ0BQYwIQYwIKAIAQX4gAndxNgIADAILIAZBEEEUIAYoAhAgBUYbaiABNgIAIAFFDQELIAEgBjYCGCAFKAIQIgIEQCABIAI2AhAgAiABNgIYCyAFKAIUIgJFDQAgASACNgIUIAIgATYCGAsgAyAAQQFyNgIEIAAgA2ogADYCACADQZwIKAIARw0BQZAIIAA2AgAPCyAFIAFBfnE2AgQgAyAAQQFyNgIEIAAgA2ogADYCAAsgAEH/AU0EQCAAQQN2IgFBA3RBsAhqIQACf0GICCgCACICQQEgAXQiAXFFBEBBiAggASACcjYCACAADAELIAAoAggLIQIgACADNgIIIAIgAzYCDCADIAA2AgwgAyACNgIIDwtBHyECIANCADcCECAAQf///wdNBEAgAEEIdiIBIAFBgP4/akEQdkEIcSIBdCICIAJBgOAfakEQdkEEcSICdCIEIARBgIAPakEQdkECcSIEdEEPdiABIAJyIARyayIBQQF0IAAgAUEVanZBAXFyQRxqIQILIAMgAjYCHCACQQJ0QbgKaiEBAkACQAJAQYwIKAIAIgRBASACdCIHcUUEQEGMCCAEIAdyNgIAIAEgAzYCACADIAE2AhgMAQsgAEEAQRkgAkEBdmsgAkEfRht0IQIgASgCACEBA0AgASIEKAIEQXhxIABGDQIgAkEddiEBIAJBAXQhAiAEIAFBBHFqIgdBEGooAgAiAQ0ACyAHIAM2AhAgAyAENgIYCyADIAM2AgwgAyADNgIIDAELIAQoAggiACADNgIMIAQgAzYCCCADQQA2AhggAyAENgIMIAMgADYCCAtBqAhBqAgoAgBBAWsiAEF/IAAbNgIACwsLCQEAQYEICwIGUA==",!fe.startsWith(X)){var se=fe;fe=e.locateFile?e.locateFile(se,l):l+se}function ze(){var z=fe;try{if(z==fe&&C)return new Uint8Array(C);var ue=kn(z);if(ue)return ue;if(g)return g(z);throw"both async and sync fetching of the wasm failed"}catch(xe){H(xe)}}function _t(){if(!C&&(a||c)){if(typeof fetch=="function"&&!fe.startsWith("file://"))return fetch(fe,{credentials:"same-origin"}).then(function(z){if(!z.ok)throw"failed to load wasm binary file at '"+fe+"'";return z.arrayBuffer()}).catch(function(){return ze()});if(h)return new Promise(function(z,ue){h(fe,function(xe){z(new Uint8Array(xe))},ue)})}return Promise.resolve().then(function(){return ze()})}function An(z){for(;0<z.length;){var ue=z.shift();if(typeof ue=="function")ue(e);else{var xe=ue.m;typeof xe=="number"?ue.l===void 0?re.get(xe)():re.get(xe)(ue.l):xe(ue.l===void 0?null:ue.l)}}}var pr=!1,gr=typeof atob=="function"?atob:function(z){var ue="",xe=0;z=z.replace(/[^A-Za-z0-9\+\/=]/g,"");do{var Pe="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(z.charAt(xe++)),je="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(z.charAt(xe++)),Nt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(z.charAt(xe++)),En="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(z.charAt(xe++));Pe=Pe<<2|je>>4,je=(je&15)<<4|Nt>>2;var tn=(Nt&3)<<6|En;ue+=String.fromCharCode(Pe),Nt!==64&&(ue+=String.fromCharCode(je)),En!==64&&(ue+=String.fromCharCode(tn))}while(xe<z.length);return ue};function kn(z){if(z.startsWith(X)){if(z=z.slice(X.length),typeof f=="boolean"&&f){var ue=Buffer.from(z,"base64");ue=new Uint8Array(ue.buffer,ue.byteOffset,ue.byteLength)}else try{var xe=gr(z),Pe=new Uint8Array(xe.length);for(z=0;z<xe.length;++z)Pe[z]=xe.charCodeAt(z);ue=Pe}catch{throw Error("Converting base64 string to bytes failed.")}return ue}}var mr={a:function(z){var ue=U.length;if(z>>>=0,2147483648<z)return!1;for(var xe=1;4>=xe;xe*=2){var Pe=ue*(1+.2/xe);Pe=Math.min(Pe,z+100663296),Pe=Math.max(z,Pe),0<Pe%65536&&(Pe+=65536-Pe%65536);e:{try{F.grow(Math.min(2147483648,Pe)-w.byteLength+65535>>>16),R();var je=1;break e}catch{}je=void 0}if(je)return!0}return!1}};(function(){function z(je){e.asm=je.exports,F=e.asm.b,R(),re=e.asm.j,Y.unshift(e.asm.c),D--,e.monitorRunDependencies&&e.monitorRunDependencies(D),D==0&&(v!==null&&(clearInterval(v),v=null),N&&(je=N,N=null,je()))}function ue(je){z(je.instance)}function xe(je){return _t().then(function(Nt){return WebAssembly.instantiate(Nt,Pe)}).then(je,function(Nt){b("failed to asynchronously prepare wasm: "+Nt),H(Nt)})}var Pe={a:mr};if(D++,e.monitorRunDependencies&&e.monitorRunDependencies(D),e.instantiateWasm)try{return e.instantiateWasm(Pe,z)}catch(je){return b("Module.instantiateWasm callback failed with error: "+je),!1}return(function(){return C||typeof WebAssembly.instantiateStreaming!="function"||fe.startsWith(X)||fe.startsWith("file://")||typeof fetch!="function"?xe(ue):fetch(fe,{credentials:"same-origin"}).then(function(je){return WebAssembly.instantiateStreaming(je,Pe).then(ue,function(Nt){return b("wasm streaming compile failed: "+Nt),b("falling back to ArrayBuffer instantiation"),xe(ue)})})})().catch(s),{}})(),e.___wasm_call_ctors=function(){return(e.___wasm_call_ctors=e.asm.c).apply(null,arguments)},e._poly1305_auth=function(){return(e._poly1305_auth=e.asm.d).apply(null,arguments)};var jr=e.stackSave=function(){return(jr=e.stackSave=e.asm.e).apply(null,arguments)},Mi=e.stackRestore=function(){return(Mi=e.stackRestore=e.asm.f).apply(null,arguments)},Xr=e.stackAlloc=function(){return(Xr=e.stackAlloc=e.asm.g).apply(null,arguments)};e._malloc=function(){return(e._malloc=e.asm.h).apply(null,arguments)},e._free=function(){return(e._free=e.asm.i).apply(null,arguments)},e.cwrap=function(z,ue,xe,Pe){xe=xe||[];var je=xe.every(function(Nt){return Nt==="number"});return ue!=="string"&&je&&!Pe?ee(z):function(){return O(z,ue,xe,arguments)}};var Ar;N=function z(){Ar||Er(),Ar||(N=z)};function Er(){function z(){if(!Ar&&(Ar=!0,e.calledRun=!0,!k)){if(An(Y),r(e),e.onRuntimeInitialized&&e.onRuntimeInitialized(),e.postRun)for(typeof e.postRun=="function"&&(e.postRun=[e.postRun]);e.postRun.length;){var ue=e.postRun.shift();te.unshift(ue)}An(te)}}if(!(0<D)){if(e.preRun)for(typeof e.preRun=="function"&&(e.preRun=[e.preRun]);e.preRun.length;)ce();An(G),0<D||(e.setStatus?(e.setStatus("Running..."),setTimeout(function(){setTimeout(function(){e.setStatus("")},1),z()},1)):z())}}if(e.run=Er,e.preInit)for(typeof e.preInit=="function"&&(e.preInit=[e.preInit]);0<e.preInit.length;)e.preInit.pop()();return Er(),t.ready})})();typeof Es=="object"&&typeof Do=="object"?Do.exports=Uo:typeof define=="function"&&define.amd?define([],function(){return Uo}):typeof Es=="object"&&(Es.createPoly1305=Uo)});var Kn=at((Ox,Nu)=>{"use strict";var{createCipheriv:Dr,createDecipheriv:_s,createHmac:Oo,randomFillSync:lr,timingSafeEqual:Mo}=require("crypto"),{readUInt32BE:pi,writeUInt32BE:sn}=hn(),Vn=Buffer[Symbol.species],vu=2**32-1,ku=Buffer.alloc(0),Ur=Buffer.alloc(4),ys=new Map,ur=35e3,$o,ea,ta,na,ra,ia,sa;try{$o=require("./crypto/build/Release/sshcrypto.node"),{AESGCMCipher:ea,ChaChaPolyCipher:ta,GenericCipher:na,AESGCMDecipher:ra,ChaChaPolyDecipher:ia,GenericDecipher:sa}=$o}catch{}var Ft=1,xg=(()=>{function n(t,e,r,s,i,o,a){return{sslName:t,blockLen:e,keyLen:r,ivLen:s!==0||a&Ft?s:e,authLen:i,discardLen:o,stream:!!(a&Ft)}}return{"chacha20-poly1305@openssh.com":n("chacha20",8,64,0,16,0,Ft),"aes128-gcm":n("aes-128-gcm",16,16,12,16,0,Ft),"aes256-gcm":n("aes-256-gcm",16,32,12,16,0,Ft),"aes128-gcm@openssh.com":n("aes-128-gcm",16,16,12,16,0,Ft),"aes256-gcm@openssh.com":n("aes-256-gcm",16,32,12,16,0,Ft),"aes128-cbc":n("aes-128-cbc",16,16,0,0,0,0),"aes192-cbc":n("aes-192-cbc",16,24,0,0,0,0),"aes256-cbc":n("aes-256-cbc",16,32,0,0,0,0),"rijndael-cbc@lysator.liu.se":n("aes-256-cbc",16,32,0,0,0,0),"3des-cbc":n("des-ede3-cbc",8,24,0,0,0,0),"blowfish-cbc":n("bf-cbc",8,16,0,0,0,0),"idea-cbc":n("idea-cbc",8,16,0,0,0,0),"cast128-cbc":n("cast-cbc",8,16,0,0,0,0),"aes128-ctr":n("aes-128-ctr",16,16,16,0,0,Ft),"aes192-ctr":n("aes-192-ctr",16,24,16,0,0,Ft),"aes256-ctr":n("aes-256-ctr",16,32,16,0,0,Ft),"3des-ctr":n("des-ede3",8,24,8,0,0,Ft),"blowfish-ctr":n("bf-ecb",8,16,8,0,0,Ft),"cast128-ctr":n("cast5-ecb",8,16,8,0,0,Ft),arcfour:n("rc4",8,16,0,0,1536,Ft),arcfour128:n("rc4",8,16,0,0,1536,Ft),arcfour256:n("rc4",8,32,0,0,1536,Ft),arcfour512:n("rc4",8,64,0,0,1536,Ft)}})(),Sg=(()=>{function n(t,e,r,s){return{sslName:t,len:e,actualLen:r,isETM:s}}return{"hmac-md5":n("md5",16,16,!1),"hmac-md5-96":n("md5",16,12,!1),"hmac-ripemd160":n("ripemd160",20,20,!1),"hmac-sha1":n("sha1",20,20,!1),"hmac-sha1-etm@openssh.com":n("sha1",20,20,!0),"hmac-sha1-96":n("sha1",20,12,!1),"hmac-sha2-256":n("sha256",32,32,!1),"hmac-sha2-256-etm@openssh.com":n("sha256",32,32,!0),"hmac-sha2-256-96":n("sha256",32,12,!1),"hmac-sha2-512":n("sha512",64,64,!1),"hmac-sha2-512-etm@openssh.com":n("sha512",64,64,!0),"hmac-sha2-512-96":n("sha512",64,12,!1)}})(),Fo=class{constructor(t,e){this.outSeqno=t,this._onWrite=e,this._dead=!1}free(){this._dead=!0}allocPacket(t){let e=5+t,r=8-(e&7);r<4&&(r+=8),e+=r;let s=Buffer.allocUnsafe(e);return sn(s,e-4,0),s[4]=r,lr(s,5+t,r),s}encrypt(t){this._dead||(this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},Bu=Buffer.alloc(32),Xt=Buffer.alloc(16),hi,gi,oa,Ho=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._encKeyMain=e.cipherKey.slice(0,32),this._encKeyPktLen=e.cipherKey.slice(32),this._dead=!1}free(){this._dead=!0}allocPacket(t){let e=5+t,r=8-(e-4&7);r<4&&(r+=8),e+=r;let s=Buffer.allocUnsafe(e);return sn(s,e-4,0),s[4]=r,lr(s,5+t,r),s}encrypt(t){if(this._dead)return;Xt[0]=0,sn(Xt,this.outSeqno,12);let e=Dr("chacha20",this._encKeyMain,Xt).update(Bu),r=Dr("chacha20",this._encKeyPktLen,Xt).update(t.slice(0,4));this._onWrite(r),Xt[0]=1;let s=Dr("chacha20",this._encKeyMain,Xt).update(t.slice(4));this._onWrite(s),oa(gi,r,r.length,s,s.length,e);let i=Buffer.allocUnsafe(16);i.set(new Uint8Array(hi.HEAPU8.buffer,gi,16),0),this._onWrite(i),this.outSeqno=this.outSeqno+1>>>0}},Qo=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._instance=new ta(e.cipherKey),this._dead=!1}free(){this._dead=!0,this._instance.free()}allocPacket(t){let e=5+t,r=8-(e-4&7);r<4&&(r+=8),e+=r;let s=Buffer.allocUnsafe(e+16);return sn(s,e-4,0),s[4]=r,lr(s,5+t,r),s}encrypt(t){this._dead||(this._instance.encrypt(t,this.outSeqno),this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},Wo=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._encSSLName=e.cipherInfo.sslName,this._encKey=e.cipherKey,this._encIV=e.cipherIV,this._dead=!1}free(){this._dead=!0}allocPacket(t){let e=5+t,r=16-(e-4&15);r<4&&(r+=16),e+=r;let s=Buffer.allocUnsafe(e);return sn(s,e-4,0),s[4]=r,lr(s,5+t,r),s}encrypt(t){if(this._dead)return;let e=Dr(this._encSSLName,this._encKey,this._encIV);e.setAutoPadding(!1);let r=t.slice(0,4);e.setAAD(r),this._onWrite(r);let s=e.update(t.slice(4));this._onWrite(s);let i=e.final();i.length&&this._onWrite(i);let o=e.getAuthTag();this._onWrite(o),Ru(this._encIV),this.outSeqno=this.outSeqno+1>>>0}},qo=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._instance=new ea(e.cipherInfo.sslName,e.cipherKey,e.cipherIV),this._dead=!1}free(){this._dead=!0,this._instance.free()}allocPacket(t){let e=5+t,r=16-(e-4&15);r<4&&(r+=16),e+=r;let s=Buffer.allocUnsafe(e+16);return sn(s,e-4,0),s[4]=r,lr(s,5+t,r),s}encrypt(t){this._dead||(this._instance.encrypt(t),this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},Ko=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._encBlockLen=e.cipherInfo.blockLen,this._cipherInstance=Dr(e.cipherInfo.sslName,e.cipherKey,e.cipherIV),this._macSSLName=e.macInfo.sslName,this._macKey=e.macKey,this._macActualLen=e.macInfo.actualLen,this._macETM=e.macInfo.isETM,this._aadLen=this._macETM?4:0,this._dead=!1;let r=e.cipherInfo.discardLen;if(r){let s=ys.get(r);s===void 0&&(s=Buffer.alloc(r),ys.set(r,s)),this._cipherInstance.update(s)}}free(){this._dead=!0}allocPacket(t){let e=this._encBlockLen,r=5+t,s=e-(r-this._aadLen&e-1);s<4&&(s+=e),r+=s;let i=Buffer.allocUnsafe(r);return sn(i,r-4,0),i[4]=s,lr(i,5+t,s),i}encrypt(t){if(this._dead)return;let e;if(this._macETM){let s=new Uint8Array(t.buffer,t.byteOffset,4),i=this._cipherInstance.update(new Uint8Array(t.buffer,t.byteOffset+4,t.length-4));this._onWrite(s),this._onWrite(i),e=Oo(this._macSSLName,this._macKey),sn(Ur,this.outSeqno,0),e.update(Ur),e.update(s),e.update(i)}else{let s=this._cipherInstance.update(t);this._onWrite(s),e=Oo(this._macSSLName,this._macKey),sn(Ur,this.outSeqno,0),e.update(Ur),e.update(t)}let r=e.digest();r.length>this._macActualLen&&(r=r.slice(0,this._macActualLen)),this._onWrite(r),this.outSeqno=this.outSeqno+1>>>0}},Vo=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._encBlockLen=e.cipherInfo.blockLen,this._macLen=e.macInfo.len,this._macActualLen=e.macInfo.actualLen,this._aadLen=e.macInfo.isETM?4:0,this._instance=new na(e.cipherInfo.sslName,e.cipherKey,e.cipherIV,e.macInfo.sslName,e.macKey,e.macInfo.isETM),this._dead=!1}free(){this._dead=!0,this._instance.free()}allocPacket(t){let e=this._encBlockLen,r=5+t,s=e-(r-this._aadLen&e-1);s<4&&(s+=e),r+=s;let i=Buffer.allocUnsafe(r+this._macLen);return sn(i,r-4,0),i[4]=s,lr(i,5+t,s),i}encrypt(t){this._dead||(this._instance.encrypt(t,this.outSeqno),this._macActualLen<this._macLen&&(t=new Vn(t.buffer,t.byteOffset,t.length-(this._macLen-this._macActualLen))),this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},Go=class{constructor(t,e){this.inSeqno=t,this._onPayload=e,this._len=0,this._lenBytes=0,this._packet=null,this._packetPos=0}free(){}decrypt(t,e,r){for(;e<r;){if(this._lenBytes<4){let i=Math.min(4-this._lenBytes,r-e);for(this._lenBytes+=i;i--;)this._len=(this._len<<8)+t[e++];if(this._lenBytes<4)return;if(this._len>ur||this._len<8||(4+this._len&7)!==0)throw new Error("Bad packet length");if(e>=r)return}if(this._packetPos<this._len){let i=Math.min(this._len-this._packetPos,r-e),o;if(e!==0||i!==r?o=new Uint8Array(t.buffer,t.byteOffset+e,i):o=t,i===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._packetPos)),e+=i,this._packetPos+=i,this._packetPos<this._len)return}let s=this._packet?new Vn(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1):ku;this.inSeqno=this.inSeqno+1>>>0,this._len=0,this._lenBytes=0,this._packet=null,this._packetPos=0;{let i=this._onPayload(s);if(i!==void 0)return i===!1?e:i}}}},Yo=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._decKeyMain=e.decipherKey.slice(0,32),this._decKeyPktLen=e.decipherKey.slice(32),this._len=0,this._lenBuf=Buffer.alloc(4),this._lenPos=0,this._packet=null,this._pktLen=0,this._mac=Buffer.allocUnsafe(16),this._calcMac=Buffer.allocUnsafe(16),this._macPos=0}free(){}decrypt(t,e,r){for(;e<r;){if(this._lenPos<4){let a=Math.min(4-this._lenPos,r-e);for(;a--;)this._lenBuf[this._lenPos++]=t[e++];if(this._lenPos<4)return;Xt[0]=0,sn(Xt,this.inSeqno,12);let c=_s("chacha20",this._decKeyPktLen,Xt).update(this._lenBuf);if(this._len=pi(c,0),this._len>ur||this._len<8||(this._len&7)!==0)throw new Error("Bad packet length")}if(this._pktLen<this._len){if(e>=r)return;let a=Math.min(this._len-this._pktLen,r-e),c;if(e!==0||a!==r?c=new Uint8Array(t.buffer,t.byteOffset+e,a):c=t,a===this._len?this._packet=c:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(c,this._pktLen)),e+=a,this._pktLen+=a,this._pktLen<this._len||e>=r)return}{let a=Math.min(16-this._macPos,r-e);if(e!==0||a!==r?this._mac.set(new Uint8Array(t.buffer,t.byteOffset+e,a),this._macPos):this._mac.set(t,this._macPos),e+=a,this._macPos+=a,this._macPos<16)return}Xt[0]=0,sn(Xt,this.inSeqno,12);let s=Dr("chacha20",this._decKeyMain,Xt).update(Bu);if(oa(gi,this._lenBuf,4,this._packet,this._packet.length,s),this._calcMac.set(new Uint8Array(hi.HEAPU8.buffer,gi,16),0),!Mo(this._calcMac,this._mac))throw new Error("Invalid MAC");Xt[0]=1;let i=_s("chacha20",this._decKeyMain,Xt).update(this._packet),o=new Vn(i.buffer,i.byteOffset+1,i.length-i[0]-1);this.inSeqno=this.inSeqno+1>>>0,this._len=0,this._lenPos=0,this._packet=null,this._pktLen=0,this._macPos=0;{let a=this._onPayload(o);if(a!==void 0)return a===!1?e:a}}}},zo=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._instance=new ia(e.decipherKey),this._len=0,this._lenBuf=Buffer.alloc(4),this._lenPos=0,this._packet=null,this._pktLen=0,this._mac=Buffer.allocUnsafe(16),this._macPos=0}free(){this._instance.free()}decrypt(t,e,r){for(;e<r;){if(this._lenPos<4){let i=Math.min(4-this._lenPos,r-e);for(;i--;)this._lenBuf[this._lenPos++]=t[e++];if(this._lenPos<4)return;if(this._len=this._instance.decryptLen(this._lenBuf,this.inSeqno),this._len>ur||this._len<8||(this._len&7)!==0)throw new Error("Bad packet length");if(e>=r)return}if(this._pktLen<this._len){let i=Math.min(this._len-this._pktLen,r-e),o;if(e!==0||i!==r?o=new Uint8Array(t.buffer,t.byteOffset+e,i):o=t,i===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._pktLen)),e+=i,this._pktLen+=i,this._pktLen<this._len||e>=r)return}{let i=Math.min(16-this._macPos,r-e);if(e!==0||i!==r?this._mac.set(new Uint8Array(t.buffer,t.byteOffset+e,i),this._macPos):this._mac.set(t,this._macPos),e+=i,this._macPos+=i,this._macPos<16)return}this._instance.decrypt(this._packet,this._mac,this.inSeqno);let s=new Vn(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1);this.inSeqno=this.inSeqno+1>>>0,this._len=0,this._lenPos=0,this._packet=null,this._pktLen=0,this._macPos=0;{let i=this._onPayload(s);if(i!==void 0)return i===!1?e:i}}}},jo=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._decipherInstance=null,this._decipherSSLName=e.decipherInfo.sslName,this._decipherKey=e.decipherKey,this._decipherIV=e.decipherIV,this._len=0,this._lenBytes=0,this._packet=null,this._packetPos=0,this._pktLen=0,this._tag=Buffer.allocUnsafe(16),this._tagPos=0}free(){}decrypt(t,e,r){for(;e<r;){if(this._lenBytes<4){let i=Math.min(4-this._lenBytes,r-e);for(this._lenBytes+=i;i--;)this._len=(this._len<<8)+t[e++];if(this._lenBytes<4)return;if(this._len+20>ur||this._len<16||(this._len&15)!==0)throw new Error("Bad packet length");this._decipherInstance=_s(this._decipherSSLName,this._decipherKey,this._decipherIV),this._decipherInstance.setAutoPadding(!1),this._decipherInstance.setAAD(wg(this._len))}if(this._pktLen<this._len){if(e>=r)return;let i=Math.min(this._len-this._pktLen,r-e),o;if(e!==0||i!==r?o=this._decipherInstance.update(new Uint8Array(t.buffer,t.byteOffset+e,i)):o=this._decipherInstance.update(t),o.length&&(i===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._packetPos)),this._packetPos+=o.length),e+=i,this._pktLen+=i,this._pktLen<this._len||e>=r)return}{let i=Math.min(16-this._tagPos,r-e);if(e!==0||i!==r?this._tag.set(new Uint8Array(t.buffer,t.byteOffset+e,i),this._tagPos):this._tag.set(t,this._tagPos),e+=i,this._tagPos+=i,this._tagPos<16)return}{this._decipherInstance.setAuthTag(this._tag);let i=this._decipherInstance.final();i.length&&(this._packet?this._packet.set(i,this._packetPos):this._packet=i)}let s=this._packet?new Vn(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1):ku;this.inSeqno=this.inSeqno+1>>>0,Ru(this._decipherIV),this._len=0,this._lenBytes=0,this._packet=null,this._packetPos=0,this._pktLen=0,this._tagPos=0;{let i=this._onPayload(s);if(i!==void 0)return i===!1?e:i}}}},Xo=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._instance=new ra(e.decipherInfo.sslName,e.decipherKey,e.decipherIV),this._len=0,this._lenBytes=0,this._packet=null,this._pktLen=0,this._tag=Buffer.allocUnsafe(16),this._tagPos=0}free(){}decrypt(t,e,r){for(;e<r;){if(this._lenBytes<4){let i=Math.min(4-this._lenBytes,r-e);for(this._lenBytes+=i;i--;)this._len=(this._len<<8)+t[e++];if(this._lenBytes<4)return;if(this._len+20>ur||this._len<16||(this._len&15)!==0)throw new Error(`Bad packet length: ${this._len}`)}if(this._pktLen<this._len){if(e>=r)return;let i=Math.min(this._len-this._pktLen,r-e),o;if(e!==0||i!==r?o=new Uint8Array(t.buffer,t.byteOffset+e,i):o=t,i===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._pktLen)),e+=i,this._pktLen+=i,this._pktLen<this._len||e>=r)return}{let i=Math.min(16-this._tagPos,r-e);if(e!==0||i!==r?this._tag.set(new Uint8Array(t.buffer,t.byteOffset+e,i),this._tagPos):this._tag.set(t,this._tagPos),e+=i,this._tagPos+=i,this._tagPos<16)return}this._instance.decrypt(this._packet,this._len,this._tag);let s=new Vn(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1);this.inSeqno=this.inSeqno+1>>>0,this._len=0,this._lenBytes=0,this._packet=null,this._pktLen=0,this._tagPos=0;{let i=this._onPayload(s);if(i!==void 0)return i===!1?e:i}}}},Jo=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._decipherInstance=_s(e.decipherInfo.sslName,e.decipherKey,e.decipherIV),this._decipherInstance.setAutoPadding(!1),this._block=Buffer.allocUnsafe(e.macInfo.isETM?4:e.decipherInfo.blockLen),this._blockSize=e.decipherInfo.blockLen,this._blockPos=0,this._len=0,this._packet=null,this._packetPos=0,this._pktLen=0,this._mac=Buffer.allocUnsafe(e.macInfo.actualLen),this._macPos=0,this._macSSLName=e.macInfo.sslName,this._macKey=e.macKey,this._macActualLen=e.macInfo.actualLen,this._macETM=e.macInfo.isETM,this._macInstance=null;let r=e.decipherInfo.discardLen;if(r){let s=ys.get(r);s===void 0&&(s=Buffer.alloc(r),ys.set(r,s)),this._decipherInstance.update(s)}}free(){}decrypt(t,e,r){for(;e<r;){if(this._blockPos<this._block.length){let o=Math.min(this._block.length-this._blockPos,r-e);if(e!==0||o!==r||o<t.length?this._block.set(new Uint8Array(t.buffer,t.byteOffset+e,o),this._blockPos):this._block.set(t,this._blockPos),e+=o,this._blockPos+=o,this._blockPos<this._block.length)return;let a,c;if(this._macETM?this._len=c=pi(this._block,0):(a=this._decipherInstance.update(this._block),this._len=pi(a,0),c=4+this._len-this._blockSize),this._len>ur||this._len<5||(c&this._blockSize-1)!==0)throw new Error("Bad packet length");if(this._macInstance=Oo(this._macSSLName,this._macKey),sn(Ur,this.inSeqno,0),this._macInstance.update(Ur),this._macETM?this._macInstance.update(this._block):(this._macInstance.update(new Uint8Array(a.buffer,a.byteOffset,4)),this._pktLen=a.length-4,this._packetPos=this._pktLen,this._packet=Buffer.allocUnsafe(this._len),this._packet.set(new Uint8Array(a.buffer,a.byteOffset+4,this._packetPos),0)),e>=r)return}if(this._pktLen<this._len){let o=Math.min(this._len-this._pktLen,r-e),a;e!==0||o!==r?a=new Uint8Array(t.buffer,t.byteOffset+e,o):a=t,this._macETM&&this._macInstance.update(a);let c=this._decipherInstance.update(a);if(c.length&&(o===this._len?this._packet=c:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(c,this._packetPos)),this._packetPos+=c.length),e+=o,this._pktLen+=o,this._pktLen<this._len||e>=r)return}{let o=Math.min(this._macActualLen-this._macPos,r-e);if(e!==0||o!==r?this._mac.set(new Uint8Array(t.buffer,t.byteOffset+e,o),this._macPos):this._mac.set(t,this._macPos),e+=o,this._macPos+=o,this._macPos<this._macActualLen)return}this._macETM||this._macInstance.update(this._packet);let s=this._macInstance.digest();if(this._macActualLen<s.length&&(s=new Uint8Array(s.buffer,s.byteOffset,this._macActualLen)),!Ig(s,this._mac))throw new Error("Invalid MAC");let i=new Vn(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1);this.inSeqno=this.inSeqno+1>>>0,this._blockPos=0,this._len=0,this._packet=null,this._packetPos=0,this._pktLen=0,this._macPos=0,this._macInstance=null;{let o=this._onPayload(i);if(o!==void 0)return o===!1?e:o}}}},Zo=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._instance=new sa(e.decipherInfo.sslName,e.decipherKey,e.decipherIV,e.macInfo.sslName,e.macKey,e.macInfo.isETM,e.macInfo.actualLen),this._block=Buffer.allocUnsafe(e.macInfo.isETM||e.decipherInfo.stream?4:e.decipherInfo.blockLen),this._blockPos=0,this._len=0,this._packet=null,this._pktLen=0,this._mac=Buffer.allocUnsafe(e.macInfo.actualLen),this._macPos=0,this._macActualLen=e.macInfo.actualLen,this._macETM=e.macInfo.isETM}free(){this._instance.free()}decrypt(t,e,r){for(;e<r;){if(this._blockPos<this._block.length){let i=Math.min(this._block.length-this._blockPos,r-e);if(e!==0||i!==r||i<t.length?this._block.set(new Uint8Array(t.buffer,t.byteOffset+e,i),this._blockPos):this._block.set(t,this._blockPos),e+=i,this._blockPos+=i,this._blockPos<this._block.length)return;let o;if(this._macETM?this._len=o=pi(this._block,0):(this._instance.decryptBlock(this._block),this._len=pi(this._block,0),o=4+this._len-this._block.length),this._len>ur||this._len<5||(o&this._block.length-1)!==0)throw new Error("Bad packet length");if(this._macETM||(this._pktLen=this._block.length-4,this._pktLen&&(this._packet=Buffer.allocUnsafe(this._len),this._packet.set(new Uint8Array(this._block.buffer,this._block.byteOffset+4,this._pktLen),0))),e>=r)return}if(this._pktLen<this._len){let i=Math.min(this._len-this._pktLen,r-e),o;if(e!==0||i!==r?o=new Uint8Array(t.buffer,t.byteOffset+e,i):o=t,i===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._pktLen)),e+=i,this._pktLen+=i,this._pktLen<this._len||e>=r)return}{let i=Math.min(this._macActualLen-this._macPos,r-e);if(e!==0||i!==r?this._mac.set(new Uint8Array(t.buffer,t.byteOffset+e,i),this._macPos):this._mac.set(t,this._macPos),e+=i,this._macPos+=i,this._macPos<this._macActualLen)return}this._instance.decrypt(this._packet,this.inSeqno,this._block,this._mac);let s=new Vn(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1);this.inSeqno=this.inSeqno+1>>>0,this._blockPos=0,this._len=0,this._packet=null,this._pktLen=0,this._macPos=0,this._macInstance=null;{let i=this._onPayload(s);if(i!==void 0)return i===!1?e:i}}}};function Ru(n){++n[11]>>>8&&++n[10]>>>8&&++n[9]>>>8&&++n[8]>>>8&&++n[7]>>>8&&++n[6]>>>8&&++n[5]>>>8&&++n[4]>>>8}var wg=(()=>{let n=Buffer.alloc(4);return t=>(n[0]=t>>>24,n[1]=t>>>16,n[2]=t>>>8,n[3]=t,n)})();function Ig(n,t){return n.length!==t.length?(Mo(n,n),!1):Mo(n,t)}function Cg(n){if(typeof n!="object"||n===null)throw new Error("Invalid config");if(typeof n.outbound!="object"||n.outbound===null)throw new Error("Invalid outbound");let t=n.outbound;if(typeof t.onWrite!="function")throw new Error("Invalid outbound.onWrite");if(typeof t.cipherInfo!="object"||t.cipherInfo===null)throw new Error("Invalid outbound.cipherInfo");if(!Buffer.isBuffer(t.cipherKey)||t.cipherKey.length!==t.cipherInfo.keyLen)throw new Error("Invalid outbound.cipherKey");if(t.cipherInfo.ivLen&&(!Buffer.isBuffer(t.cipherIV)||t.cipherIV.length!==t.cipherInfo.ivLen))throw new Error("Invalid outbound.cipherIV");if(typeof t.seqno!="number"||t.seqno<0||t.seqno>vu)throw new Error("Invalid outbound.seqno");let e=!!t.forceNative;switch(t.cipherInfo.sslName){case"aes-128-gcm":case"aes-256-gcm":return ea&&!e?new qo(n):new Wo(n);case"chacha20":return ta&&!e?new Qo(n):new Ho(n);default:{if(typeof t.macInfo!="object"||t.macInfo===null)throw new Error("Invalid outbound.macInfo");if(!Buffer.isBuffer(t.macKey)||t.macKey.length!==t.macInfo.len)throw new Error("Invalid outbound.macKey");return na&&!e?new Vo(n):new Ko(n)}}}function vg(n){if(typeof n!="object"||n===null)throw new Error("Invalid config");if(typeof n.inbound!="object"||n.inbound===null)throw new Error("Invalid inbound");let t=n.inbound;if(typeof t.onPayload!="function")throw new Error("Invalid inbound.onPayload");if(typeof t.decipherInfo!="object"||t.decipherInfo===null)throw new Error("Invalid inbound.decipherInfo");if(!Buffer.isBuffer(t.decipherKey)||t.decipherKey.length!==t.decipherInfo.keyLen)throw new Error("Invalid inbound.decipherKey");if(t.decipherInfo.ivLen&&(!Buffer.isBuffer(t.decipherIV)||t.decipherIV.length!==t.decipherInfo.ivLen))throw new Error("Invalid inbound.decipherIV");if(typeof t.seqno!="number"||t.seqno<0||t.seqno>vu)throw new Error("Invalid inbound.seqno");let e=!!t.forceNative;switch(t.decipherInfo.sslName){case"aes-128-gcm":case"aes-256-gcm":return ra&&!e?new Xo(n):new jo(n);case"chacha20":return ia&&!e?new zo(n):new Yo(n);default:{if(typeof t.macInfo!="object"||t.macInfo===null)throw new Error("Invalid inbound.macInfo");if(!Buffer.isBuffer(t.macKey)||t.macKey.length!==t.macInfo.len)throw new Error("Invalid inbound.macKey");return sa&&!e?new Zo(n):new Jo(n)}}}Nu.exports={CIPHER_INFO:xg,MAC_INFO:Sg,bindingAvailable:!!$o,init:new Promise(async(n,t)=>{try{hi=await Cu()(),gi=hi._malloc(16),oa=hi.cwrap("poly1305_auth",null,["number","array","number","array","number","array"])}catch(e){return t(e)}n()}),NullCipher:Fo,createCipher:Cg,NullDecipher:Go,createDecipher:vg}});var Yn=at((Mx,Hu)=>{"use strict";var{createDecipheriv:ca,createECDH:kg,createHash:Ai,createHmac:Bg,createSign:Rg,createVerify:Ng,getCiphers:Pg,sign:Pu,verify:Tu}=require("crypto"),Tg=Pg(),{Ber:Re}=li(),Lg=No().pbkdf,{CIPHER_INFO:Ei}=Kn(),{eddsaSupported:fa,SUPPORTED_CIPHER:Ug}=Ln(),{bufferSlice:dr,makeBufferParser:Dg,readString:ve,readUInt32BE:mi,writeUInt32BE:Ot}=hn(),Un=Symbol("Hash Algorithm"),pn=Symbol("Private key PEM"),In=Symbol("Public key PEM"),Gn=Symbol("Public key SSH"),Or=Symbol("Decrypted Key"),aa=Object.create(null);{let n=Object.keys(Ei);for(let t=0;t<n.length;++t){let e=Ei[n[t]].sslName;!e||aa[e]||(aa[e]=Ei[n[t]])}}var bs=Dg();function gn(n,t){t=t.base64Slice(0,t.length);let e=t.replace(/.{64}/g,`$&
|
|
3
|
+
-----END PRIVATE KEY-----`,t=Buffer.from("a"),e,r;try{e=Nn.sign(null,t,n),r=Nn.verify(null,t,n,e)}catch{}return Buffer.isBuffer(e)&&e.length===64&&r===!0}return!1})(),Uc=typeof Nn.diffieHellman=="function"&&typeof Nn.generateKeyPairSync=="function"&&typeof Nn.createPublicKey=="function",Xi=["ecdh-sha2-nistp256","ecdh-sha2-nistp384","ecdh-sha2-nistp521","diffie-hellman-group-exchange-sha256","diffie-hellman-group14-sha256","diffie-hellman-group15-sha512","diffie-hellman-group16-sha512","diffie-hellman-group17-sha512","diffie-hellman-group18-sha512"];Uc&&(Xi.unshift("curve25519-sha256"),Xi.unshift("curve25519-sha256@libssh.org"));var rp=Xi.concat(["diffie-hellman-group-exchange-sha1","diffie-hellman-group14-sha1","diffie-hellman-group1-sha1"]),lo=["ecdsa-sha2-nistp256","ecdsa-sha2-nistp384","ecdsa-sha2-nistp521","rsa-sha2-512","rsa-sha2-256","ssh-rsa"];Lc&&lo.unshift("ssh-ed25519");var ip=lo.concat(["ssh-dss"]),Dc=(()=>{let n=Nn.getCiphers();return t=>n.includes(tp[t].sslName)})(),Hn=["aes128-gcm@openssh.com","aes256-gcm@openssh.com","aes128-ctr","aes192-ctr","aes256-ctr"];Cr&&Cr.flags&&!Cr.flags.aes?Tc?Hn.unshift("chacha20-poly1305@openssh.com"):Hn.push("chacha20-poly1305@openssh.com"):Tc&&Cr&&Cr.arch==="x86"?Hn.splice(4,0,"chacha20-poly1305@openssh.com"):Hn.push("chacha20-poly1305@openssh.com");Hn=Hn.filter(Dc);var sp=Hn.concat(["aes256-cbc","aes192-cbc","aes128-cbc","blowfish-cbc","3des-cbc","aes128-gcm","aes256-gcm","arcfour256","arcfour128","cast128-cbc","arcfour"].filter(Dc)),Oc=(()=>{let n=Nn.getHashes();return t=>n.includes(np[t].sslName)})(),Mc=["hmac-sha2-256-etm@openssh.com","hmac-sha2-512-etm@openssh.com","hmac-sha1-etm@openssh.com","hmac-sha2-256","hmac-sha2-512","hmac-sha1"].filter(Oc),op=Mc.concat(["hmac-md5","hmac-sha2-256-96","hmac-sha2-512-96","hmac-ripemd160","hmac-sha1-96","hmac-md5-96"].filter(Oc)),$c=["none","zlib@openssh.com","zlib"],ap=$c.concat([]),Ir={BAD_DHGEX:1,OLD_EXIT:2,DYN_RPORT_BUG:4,BUG_DHGEX_LARGE:8,IMPLY_RSA_SHA2_SIGALGS:16};Ji.exports={MESSAGE:{DISCONNECT:1,IGNORE:2,UNIMPLEMENTED:3,DEBUG:4,SERVICE_REQUEST:5,SERVICE_ACCEPT:6,EXT_INFO:7,KEXINIT:20,NEWKEYS:21,KEXDH_INIT:30,KEXDH_REPLY:31,KEXDH_GEX_GROUP:31,KEXDH_GEX_INIT:32,KEXDH_GEX_REPLY:33,KEXDH_GEX_REQUEST:34,KEXECDH_INIT:30,KEXECDH_REPLY:31,USERAUTH_REQUEST:50,USERAUTH_FAILURE:51,USERAUTH_SUCCESS:52,USERAUTH_BANNER:53,USERAUTH_PASSWD_CHANGEREQ:60,USERAUTH_PK_OK:60,USERAUTH_INFO_REQUEST:60,USERAUTH_INFO_RESPONSE:61,GLOBAL_REQUEST:80,REQUEST_SUCCESS:81,REQUEST_FAILURE:82,CHANNEL_OPEN:90,CHANNEL_OPEN_CONFIRMATION:91,CHANNEL_OPEN_FAILURE:92,CHANNEL_WINDOW_ADJUST:93,CHANNEL_DATA:94,CHANNEL_EXTENDED_DATA:95,CHANNEL_EOF:96,CHANNEL_CLOSE:97,CHANNEL_REQUEST:98,CHANNEL_SUCCESS:99,CHANNEL_FAILURE:100},DISCONNECT_REASON:{HOST_NOT_ALLOWED_TO_CONNECT:1,PROTOCOL_ERROR:2,KEY_EXCHANGE_FAILED:3,RESERVED:4,MAC_ERROR:5,COMPRESSION_ERROR:6,SERVICE_NOT_AVAILABLE:7,PROTOCOL_VERSION_NOT_SUPPORTED:8,HOST_KEY_NOT_VERIFIABLE:9,CONNECTION_LOST:10,BY_APPLICATION:11,TOO_MANY_CONNECTIONS:12,AUTH_CANCELED_BY_USER:13,NO_MORE_AUTH_METHODS_AVAILABLE:14,ILLEGAL_USER_NAME:15},DISCONNECT_REASON_STR:void 0,CHANNEL_OPEN_FAILURE:{ADMINISTRATIVELY_PROHIBITED:1,CONNECT_FAILED:2,UNKNOWN_CHANNEL_TYPE:3,RESOURCE_SHORTAGE:4},TERMINAL_MODE:{TTY_OP_END:0,VINTR:1,VQUIT:2,VERASE:3,VKILL:4,VEOF:5,VEOL:6,VEOL2:7,VSTART:8,VSTOP:9,VSUSP:10,VDSUSP:11,VREPRINT:12,VWERASE:13,VLNEXT:14,VFLUSH:15,VSWTCH:16,VSTATUS:17,VDISCARD:18,IGNPAR:30,PARMRK:31,INPCK:32,ISTRIP:33,INLCR:34,IGNCR:35,ICRNL:36,IUCLC:37,IXON:38,IXANY:39,IXOFF:40,IMAXBEL:41,ISIG:50,ICANON:51,XCASE:52,ECHO:53,ECHOE:54,ECHOK:55,ECHONL:56,NOFLSH:57,TOSTOP:58,IEXTEN:59,ECHOCTL:60,ECHOKE:61,PENDIN:62,OPOST:70,OLCUC:71,ONLCR:72,OCRNL:73,ONOCR:74,ONLRET:75,CS7:90,CS8:91,PARENB:92,PARODD:93,TTY_OP_ISPEED:128,TTY_OP_OSPEED:129},CHANNEL_EXTENDED_DATATYPE:{STDERR:1},SIGNALS:["ABRT","ALRM","FPE","HUP","ILL","INT","QUIT","SEGV","TERM","USR1","USR2","KILL","PIPE"].reduce((n,t)=>({...n,[t]:1}),{}),COMPAT:Ir,COMPAT_CHECKS:[["Cisco-1.25",Ir.BAD_DHGEX],[/^Cisco-1[.]/,Ir.BUG_DHGEX_LARGE],[/^[0-9.]+$/,Ir.OLD_EXIT],[/^OpenSSH_5[.][0-9]+/,Ir.DYN_RPORT_BUG],[/^OpenSSH_7[.]4/,Ir.IMPLY_RSA_SHA2_SIGALGS]],DEFAULT_KEX:Xi,SUPPORTED_KEX:rp,DEFAULT_SERVER_HOST_KEY:lo,SUPPORTED_SERVER_HOST_KEY:ip,DEFAULT_CIPHER:Hn,SUPPORTED_CIPHER:sp,DEFAULT_MAC:Mc,SUPPORTED_MAC:op,DEFAULT_COMPRESSION:$c,SUPPORTED_COMPRESSION:ap,curve25519Supported:Uc,eddsaSupported:Lc};Ji.exports.DISCONNECT_REASON_BY_VALUE=Array.from(Object.entries(Ji.exports.DISCONNECT_REASON)).reduce((n,[t,e])=>({...n,[e]:t}),{})});var dn=at((uE,Wc)=>{"use strict";var ln=ni().Ber,Zi,Qc=Buffer[Symbol.species],cp=Object.getPrototypeOf(Uint8Array.prototype).fill;function Fc(n,t){return n[t++]*16777216+n[t++]*65536+n[t++]*256+n[t]}function ri(n,t,e,r,s){s||(s=0),r>n.length&&(r=n.length);let i=r-e,o=t.length-s;return i>o&&(i=o),t.set(new Uint8Array(n.buffer,n.byteOffset+e,i),s),i}function ii(n,t,e){return e===void 0&&(e=n.length),new Qc(n.buffer,n.byteOffset+t,e-t)}function ho(){let n=0,t,e={init:(r,s)=>{t=r,n=typeof s=="number"?s:0},pos:()=>n,length:()=>t?t.length:0,avail:()=>t&&n<t.length?t.length-n:0,clear:()=>{t=void 0},readUInt32BE:()=>{if(!(!t||n+3>=t.length))return t[n++]*16777216+t[n++]*65536+t[n++]*256+t[n++]},readUInt64BE:r=>{if(!(!t||n+7>=t.length))switch(r){case"always":return BigInt(`0x${t.hexSlice(n,n+=8)}`);case"maybe":if(t[n]>31)return BigInt(`0x${t.hexSlice(n,n+=8)}`);default:return t[n++]*72057594037927940+t[n++]*281474976710656+t[n++]*1099511627776+t[n++]*4294967296+t[n++]*16777216+t[n++]*65536+t[n++]*256+t[n++]}},skip:r=>{t&&r>0&&(n+=r)},skipString:()=>{let r=e.readUInt32BE();if(r!==void 0)return n+=r,n<=t.length?r:void 0},readByte:()=>{if(t&&n<t.length)return t[n++]},readBool:()=>{if(t&&n<t.length)return!!t[n++]},readList:()=>{let r=e.readString(!0);if(r!==void 0)return r?r.split(","):[]},readString:(r,s)=>{typeof r=="number"&&(s=r,r=void 0);let i=e.readUInt32BE();if(i!==void 0&&!(t.length-n<i||typeof s=="number"&&i>s))return r?Buffer.isBuffer(r)?ri(t,r,n,n+=i):t.utf8Slice(n,n+=i):ii(t,n,n+=i)},readRaw:r=>{if(t){if(typeof r!="number")return ii(t,n,n+=t.length-n);if(t.length-n>=r)return ii(t,n,n+=r)}}};return e}function Hc(n,t,e){let r=new Error(n);return typeof t=="boolean"?(e=t,r.level="protocol"):r.level=t||"protocol",r.fatal=!!e,r}function uo(n,t,e){return n[e++]=t>>>24,n[e++]=t>>>16,n[e++]=t>>>8,n[e++]=t,e}var es=ho();Wc.exports={bufferCopy:ri,bufferSlice:ii,FastBuffer:Qc,bufferFill:(n,t,e,r)=>cp.call(n,t,e,r),makeError:Hc,doFatalError:(n,t,e,r)=>{let s;return Zi===void 0&&({DISCONNECT_REASON:Zi}=Pn()),t instanceof Error?(s=t,typeof e!="number"?r=Zi.PROTOCOL_ERROR:r=e):s=Hc(t,e,!0),typeof r!="number"&&(r=Zi.PROTOCOL_ERROR),n.disconnect(r),n._destruct(),n._onError(s),1/0},readUInt32BE:Fc,writeUInt32BE:uo,writeUInt32LE:(n,t,e)=>(n[e++]=t,n[e++]=t>>>8,n[e++]=t>>>16,n[e++]=t>>>24,e),makeBufferParser:ho,bufferParser:ho(),readString:(n,t,e,r)=>{typeof e=="number"&&(r=e,e=void 0),t===void 0&&(t=0);let s=n.length-t;if(t<0||t>=n.length||s<4)return;let i=Fc(n,t);if(s<4+i||typeof r=="number"&&i>r)return;t+=4;let o=t+i;return n._pos=o,e?Buffer.isBuffer(e)?ri(n,e,t,o):n.utf8Slice(t,o):ii(n,t,o)},sigSSHToASN1:(n,t)=>{switch(t){case"ssh-dss":{if(n.length>40)return n;let e=new ln.Writer;e.startSequence();let r=n.slice(0,20),s=n.slice(20);if(r[0]&128){let i=Buffer.allocUnsafe(21);i[0]=0,r.copy(i,1),r=i}else r[0]===0&&!(r[1]&128)&&(r=r.slice(1));if(s[0]&128){let i=Buffer.allocUnsafe(21);i[0]=0,s.copy(i,1),s=i}else s[0]===0&&!(s[1]&128)&&(s=s.slice(1));return e.writeBuffer(r,ln.Integer),e.writeBuffer(s,ln.Integer),e.endSequence(),e.buffer}case"ecdsa-sha2-nistp256":case"ecdsa-sha2-nistp384":case"ecdsa-sha2-nistp521":{es.init(n,0);let e=es.readString(),r=es.readString();if(es.clear(),e===void 0||r===void 0)return;let s=new ln.Writer;return s.startSequence(),s.writeBuffer(e,ln.Integer),s.writeBuffer(r,ln.Integer),s.endSequence(),s.buffer}default:return n}},convertSignature:(n,t)=>{switch(t){case"ssh-dss":{if(n.length<=40)return n;let e=new ln.Reader(n);e.readSequence();let r=e.readString(ln.Integer,!0),s=e.readString(ln.Integer,!0),i=0,o=0;if(r.length<20){let c=Buffer.allocUnsafe(20);c.set(r,1),r=c,r[0]=0}if(s.length<20){let c=Buffer.allocUnsafe(20);c.set(s,1),s=c,s[0]=0}r.length>20&&r[0]===0&&(i=1),s.length>20&&s[0]===0&&(o=1);let a=Buffer.allocUnsafe(r.length-i+(s.length-o));return ri(r,a,i,r.length,0),ri(s,a,o,s.length,r.length-i),a}case"ecdsa-sha2-nistp256":case"ecdsa-sha2-nistp384":case"ecdsa-sha2-nistp521":{if(n[0]===0)return n;let e=new ln.Reader(n);e.readSequence();let r=e.readString(ln.Integer,!0),s=e.readString(ln.Integer,!0);if(r===null||s===null)return;let i=Buffer.allocUnsafe(4+r.length+4+s.length);return uo(i,r.length,0),i.set(r,4),uo(i,s.length,4+r.length),i.set(s,8+r.length),i}}return n},sendPacket:(n,t,e)=>!e&&n._kexinit!==void 0?(n._queue===void 0&&(n._queue=[]),n._queue.push(t),n._debug&&n._debug("Outbound: ... packet queued"),!1):(n._cipher.encrypt(t),!0)}});var qc=at((ts,go)=>{var po=(function(){var n=typeof document<"u"&&document.currentScript?document.currentScript.src:void 0;return typeof __filename<"u"&&(n=n||__filename),(function(t){t=t||{};var e;e||(e=typeof t<"u"?t:{});var r,s;e.ready=new Promise(function(z,ue){r=z,s=ue});var i={},o;for(o in e)e.hasOwnProperty(o)&&(i[o]=e[o]);var a=typeof window=="object",c=typeof importScripts=="function",f=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string",l="",u,h,g,y,_;f?(l=c?require("path").dirname(l)+"/":__dirname+"/",u=function(z,ue){var xe=kn(z);return xe?ue?xe:xe.toString():(y||(y=require("fs")),_||(_=require("path")),z=_.normalize(z),y.readFileSync(z,ue?null:"utf8"))},g=function(z){return z=u(z,!0),z.buffer||(z=new Uint8Array(z)),K(z.buffer),z},h=function(z,ue,xe){var Pe=kn(z);Pe&&ue(Pe),y||(y=require("fs")),_||(_=require("path")),z=_.normalize(z),y.readFile(z,function(je,Nt){je?xe(je):ue(Nt.buffer)})},1<process.argv.length&&process.argv[1].replace(/\\/g,"/"),process.argv.slice(2),e.inspect=function(){return"[Emscripten Module object]"}):(a||c)&&(c?l=self.location.href:typeof document<"u"&&document.currentScript&&(l=document.currentScript.src),n&&(l=n),l.indexOf("blob:")!==0?l=l.substr(0,l.lastIndexOf("/")+1):l="",u=function(z){try{var ue=new XMLHttpRequest;return ue.open("GET",z,!1),ue.send(null),ue.responseText}catch(je){if(z=kn(z)){ue=[];for(var xe=0;xe<z.length;xe++){var Pe=z[xe];255<Pe&&(pr&&K(!1,"Character code "+Pe+" ("+String.fromCharCode(Pe)+") at offset "+xe+" not in 0x00-0xFF."),Pe&=255),ue.push(String.fromCharCode(Pe))}return ue.join("")}throw je}},c&&(g=function(z){try{var ue=new XMLHttpRequest;return ue.open("GET",z,!1),ue.responseType="arraybuffer",ue.send(null),new Uint8Array(ue.response)}catch(xe){if(z=kn(z))return z;throw xe}}),h=function(z,ue,xe){var Pe=new XMLHttpRequest;Pe.open("GET",z,!0),Pe.responseType="arraybuffer",Pe.onload=function(){if(Pe.status==200||Pe.status==0&&Pe.response)ue(Pe.response);else{var je=kn(z);je?ue(je.buffer):xe()}},Pe.onerror=xe,Pe.send(null)}),e.print||console.log.bind(console);var b=e.printErr||console.warn.bind(console);for(o in i)i.hasOwnProperty(o)&&(e[o]=i[o]);i=null;var C;e.wasmBinary&&(C=e.wasmBinary);var L=e.noExitRuntime||!0;typeof WebAssembly!="object"&&H("no native wasm support detected");var F,k=!1;function K(z,ue){z||H("Assertion failed: "+ue)}function ee(z){var ue=e["_"+z];return K(ue,"Cannot call unknown function "+z+", make sure it is exported"),ue}function O(z,ue,xe,Pe){var je={string:function(ot){var Ut=0;if(ot!=null&&ot!==0){var Tt=(ot.length<<2)+1;Ut=Xr(Tt);var bt=Ut,ut=U;if(0<Tt){Tt=bt+Tt-1;for(var an=0;an<ot.length;++an){var xt=ot.charCodeAt(an);if(55296<=xt&&57343>=xt){var tr=ot.charCodeAt(++an);xt=65536+((xt&1023)<<10)|tr&1023}if(127>=xt){if(bt>=Tt)break;ut[bt++]=xt}else{if(2047>=xt){if(bt+1>=Tt)break;ut[bt++]=192|xt>>6}else{if(65535>=xt){if(bt+2>=Tt)break;ut[bt++]=224|xt>>12}else{if(bt+3>=Tt)break;ut[bt++]=240|xt>>18,ut[bt++]=128|xt>>12&63}ut[bt++]=128|xt>>6&63}ut[bt++]=128|xt&63}}ut[bt]=0}}return Ut},array:function(ot){var Ut=Xr(ot.length);return I.set(ot,Ut),Ut}},Nt=ee(z),En=[];if(z=0,Pe)for(var tn=0;tn<Pe.length;tn++){var _r=je[xe[tn]];_r?(z===0&&(z=jr()),En[tn]=_r(Pe[tn])):En[tn]=Pe[tn]}return xe=Nt.apply(null,En),xe=(function(ot){if(ue==="string")if(ot){for(var Ut=U,Tt=ot+NaN,bt=ot;Ut[bt]&&!(bt>=Tt);)++bt;if(16<bt-ot&&Ut.subarray&&x)ot=x.decode(Ut.subarray(ot,bt));else{for(Tt="";ot<bt;){var ut=Ut[ot++];if(ut&128){var an=Ut[ot++]&63;if((ut&224)==192)Tt+=String.fromCharCode((ut&31)<<6|an);else{var xt=Ut[ot++]&63;ut=(ut&240)==224?(ut&15)<<12|an<<6|xt:(ut&7)<<18|an<<12|xt<<6|Ut[ot++]&63,65536>ut?Tt+=String.fromCharCode(ut):(ut-=65536,Tt+=String.fromCharCode(55296|ut>>10,56320|ut&1023))}}else Tt+=String.fromCharCode(ut)}ot=Tt}}else ot="";else ot=ue==="boolean"?!!ot:ot;return ot})(xe),z!==0&&Mi(z),xe}var x=typeof TextDecoder<"u"?new TextDecoder("utf8"):void 0,w,I,U;function R(){var z=F.buffer;w=z,e.HEAP8=I=new Int8Array(z),e.HEAP16=new Int16Array(z),e.HEAP32=new Int32Array(z),e.HEAPU8=U=new Uint8Array(z),e.HEAPU16=new Uint16Array(z),e.HEAPU32=new Uint32Array(z),e.HEAPF32=new Float32Array(z),e.HEAPF64=new Float64Array(z)}var re,G=[],Y=[],te=[];function ce(){var z=e.preRun.shift();G.unshift(z)}var D=0,v=null,N=null;e.preloadedImages={},e.preloadedAudios={};function H(z){throw e.onAbort&&e.onAbort(z),b(z),k=!0,z=new WebAssembly.RuntimeError("abort("+z+"). Build with -s ASSERTIONS=1 for more info."),s(z),z}var X="data:application/octet-stream;base64,",fe;if(fe="data:application/octet-stream;base64,AGFzbQEAAAABIAZgAX8Bf2ADf39/AGABfwBgAABgAAF/YAZ/f39/f38AAgcBAWEBYQAAAwsKAAEDAQAAAgQFAgQFAXABAQEFBwEBgAKAgAIGCQF/AUGAjMACCwclCQFiAgABYwADAWQACQFlAAgBZgAHAWcABgFoAAUBaQAKAWoBAAqGTQpPAQJ/QYAIKAIAIgEgAEEDakF8cSICaiEAAkAgAkEAIAAgAU0bDQAgAD8AQRB0SwRAIAAQAEUNAQtBgAggADYCACABDwtBhAhBMDYCAEF/C4wFAg5+Cn8gACgCJCEUIAAoAiAhFSAAKAIcIREgACgCGCESIAAoAhQhEyACQRBPBEAgAC0ATEVBGHQhFyAAKAIEIhZBBWytIQ8gACgCCCIYQQVsrSENIAAoAgwiGUEFbK0hCyAAKAIQIhpBBWytIQkgADUCACEIIBqtIRAgGa0hDiAYrSEMIBatIQoDQCASIAEtAAMiEiABLQAEQQh0ciABLQAFQRB0ciABLQAGIhZBGHRyQQJ2Qf///x9xaq0iAyAOfiABLwAAIAEtAAJBEHRyIBNqIBJBGHRBgICAGHFqrSIEIBB+fCARIAEtAAdBCHQgFnIgAS0ACEEQdHIgAS0ACSIRQRh0ckEEdkH///8fcWqtIgUgDH58IAEtAApBCHQgEXIgAS0AC0EQdHIgAS0ADEEYdHJBBnYgFWqtIgYgCn58IBQgF2ogAS8ADSABLQAPQRB0cmqtIgcgCH58IAMgDH4gBCAOfnwgBSAKfnwgBiAIfnwgByAJfnwgAyAKfiAEIAx+fCAFIAh+fCAGIAl+fCAHIAt+fCADIAh+IAQgCn58IAUgCX58IAYgC358IAcgDX58IAMgCX4gBCAIfnwgBSALfnwgBiANfnwgByAPfnwiA0IaiEL/////D4N8IgRCGohC/////w+DfCIFQhqIQv////8Pg3wiBkIaiEL/////D4N8IgdCGoinQQVsIAOnQf///x9xaiITQRp2IASnQf///x9xaiESIAWnQf///x9xIREgBqdB////H3EhFSAHp0H///8fcSEUIBNB////H3EhEyABQRBqIQEgAkEQayICQQ9LDQALCyAAIBQ2AiQgACAVNgIgIAAgETYCHCAAIBI2AhggACATNgIUCwMAAQu2BAEGfwJAIAAoAjgiBARAIABBPGohBQJAIAJBECAEayIDIAIgA0kbIgZFDQAgBkEDcSEHAkAgBkEBa0EDSQRAQQAhAwwBCyAGQXxxIQhBACEDA0AgBSADIARqaiABIANqLQAAOgAAIAUgA0EBciIEIAAoAjhqaiABIARqLQAAOgAAIAUgA0ECciIEIAAoAjhqaiABIARqLQAAOgAAIAUgA0EDciIEIAAoAjhqaiABIARqLQAAOgAAIANBBGohAyAAKAI4IQQgCEEEayIIDQALCyAHRQ0AA0AgBSADIARqaiABIANqLQAAOgAAIANBAWohAyAAKAI4IQQgB0EBayIHDQALCyAAIAQgBmoiAzYCOCADQRBJDQEgACAFQRAQAiAAQQA2AjggAiAGayECIAEgBmohAQsgAkEQTwRAIAAgASACQXBxIgMQAiACQQ9xIQIgASADaiEBCyACRQ0AIAJBA3EhBCAAQTxqIQVBACEDIAJBAWtBA08EQCACQXxxIQcDQCAFIAAoAjggA2pqIAEgA2otAAA6AAAgBSADQQFyIgYgACgCOGpqIAEgBmotAAA6AAAgBSADQQJyIgYgACgCOGpqIAEgBmotAAA6AAAgBSADQQNyIgYgACgCOGpqIAEgBmotAAA6AAAgA0EEaiEDIAdBBGsiBw0ACwsgBARAA0AgBSAAKAI4IANqaiABIANqLQAAOgAAIANBAWohAyAEQQFrIgQNAAsLIAAgACgCOCACajYCOAsLoS0BDH8jAEEQayIMJAACQAJAAkACQAJAAkACQAJAAkACQAJAAkAgAEH0AU0EQEGICCgCACIFQRAgAEELakF4cSAAQQtJGyIIQQN2IgJ2IgFBA3EEQCABQX9zQQFxIAJqIgNBA3QiAUG4CGooAgAiBEEIaiEAAkAgBCgCCCICIAFBsAhqIgFGBEBBiAggBUF+IAN3cTYCAAwBCyACIAE2AgwgASACNgIICyAEIANBA3QiAUEDcjYCBCABIARqIgEgASgCBEEBcjYCBAwNCyAIQZAIKAIAIgpNDQEgAQRAAkBBAiACdCIAQQAgAGtyIAEgAnRxIgBBACAAa3FBAWsiACAAQQx2QRBxIgJ2IgFBBXZBCHEiACACciABIAB2IgFBAnZBBHEiAHIgASAAdiIBQQF2QQJxIgByIAEgAHYiAUEBdkEBcSIAciABIAB2aiIDQQN0IgBBuAhqKAIAIgQoAggiASAAQbAIaiIARgRAQYgIIAVBfiADd3EiBTYCAAwBCyABIAA2AgwgACABNgIICyAEQQhqIQAgBCAIQQNyNgIEIAQgCGoiAiADQQN0IgEgCGsiA0EBcjYCBCABIARqIAM2AgAgCgRAIApBA3YiAUEDdEGwCGohB0GcCCgCACEEAn8gBUEBIAF0IgFxRQRAQYgIIAEgBXI2AgAgBwwBCyAHKAIICyEBIAcgBDYCCCABIAQ2AgwgBCAHNgIMIAQgATYCCAtBnAggAjYCAEGQCCADNgIADA0LQYwIKAIAIgZFDQEgBkEAIAZrcUEBayIAIABBDHZBEHEiAnYiAUEFdkEIcSIAIAJyIAEgAHYiAUECdkEEcSIAciABIAB2IgFBAXZBAnEiAHIgASAAdiIBQQF2QQFxIgByIAEgAHZqQQJ0QbgKaigCACIBKAIEQXhxIAhrIQMgASECA0ACQCACKAIQIgBFBEAgAigCFCIARQ0BCyAAKAIEQXhxIAhrIgIgAyACIANJIgIbIQMgACABIAIbIQEgACECDAELCyABIAhqIgkgAU0NAiABKAIYIQsgASABKAIMIgRHBEAgASgCCCIAQZgIKAIASRogACAENgIMIAQgADYCCAwMCyABQRRqIgIoAgAiAEUEQCABKAIQIgBFDQQgAUEQaiECCwNAIAIhByAAIgRBFGoiAigCACIADQAgBEEQaiECIAQoAhAiAA0ACyAHQQA2AgAMCwtBfyEIIABBv39LDQAgAEELaiIAQXhxIQhBjAgoAgAiCUUNAEEAIAhrIQMCQAJAAkACf0EAIAhBgAJJDQAaQR8gCEH///8HSw0AGiAAQQh2IgAgAEGA/j9qQRB2QQhxIgJ0IgAgAEGA4B9qQRB2QQRxIgF0IgAgAEGAgA9qQRB2QQJxIgB0QQ92IAEgAnIgAHJrIgBBAXQgCCAAQRVqdkEBcXJBHGoLIgVBAnRBuApqKAIAIgJFBEBBACEADAELQQAhACAIQQBBGSAFQQF2ayAFQR9GG3QhAQNAAkAgAigCBEF4cSAIayIHIANPDQAgAiEEIAciAw0AQQAhAyACIQAMAwsgACACKAIUIgcgByACIAFBHXZBBHFqKAIQIgJGGyAAIAcbIQAgAUEBdCEBIAINAAsLIAAgBHJFBEBBACEEQQIgBXQiAEEAIABrciAJcSIARQ0DIABBACAAa3FBAWsiACAAQQx2QRBxIgJ2IgFBBXZBCHEiACACciABIAB2IgFBAnZBBHEiAHIgASAAdiIBQQF2QQJxIgByIAEgAHYiAUEBdkEBcSIAciABIAB2akECdEG4CmooAgAhAAsgAEUNAQsDQCAAKAIEQXhxIAhrIgEgA0khAiABIAMgAhshAyAAIAQgAhshBCAAKAIQIgEEfyABBSAAKAIUCyIADQALCyAERQ0AIANBkAgoAgAgCGtPDQAgBCAIaiIGIARNDQEgBCgCGCEFIAQgBCgCDCIBRwRAIAQoAggiAEGYCCgCAEkaIAAgATYCDCABIAA2AggMCgsgBEEUaiICKAIAIgBFBEAgBCgCECIARQ0EIARBEGohAgsDQCACIQcgACIBQRRqIgIoAgAiAA0AIAFBEGohAiABKAIQIgANAAsgB0EANgIADAkLIAhBkAgoAgAiAk0EQEGcCCgCACEDAkAgAiAIayIBQRBPBEBBkAggATYCAEGcCCADIAhqIgA2AgAgACABQQFyNgIEIAIgA2ogATYCACADIAhBA3I2AgQMAQtBnAhBADYCAEGQCEEANgIAIAMgAkEDcjYCBCACIANqIgAgACgCBEEBcjYCBAsgA0EIaiEADAsLIAhBlAgoAgAiBkkEQEGUCCAGIAhrIgE2AgBBoAhBoAgoAgAiAiAIaiIANgIAIAAgAUEBcjYCBCACIAhBA3I2AgQgAkEIaiEADAsLQQAhACAIQS9qIgkCf0HgCygCAARAQegLKAIADAELQewLQn83AgBB5AtCgKCAgICABDcCAEHgCyAMQQxqQXBxQdiq1aoFczYCAEH0C0EANgIAQcQLQQA2AgBBgCALIgFqIgVBACABayIHcSICIAhNDQpBwAsoAgAiBARAQbgLKAIAIgMgAmoiASADTQ0LIAEgBEsNCwtBxAstAABBBHENBQJAAkBBoAgoAgAiAwRAQcgLIQADQCADIAAoAgAiAU8EQCABIAAoAgRqIANLDQMLIAAoAggiAA0ACwtBABABIgFBf0YNBiACIQVB5AsoAgAiA0EBayIAIAFxBEAgAiABayAAIAFqQQAgA2txaiEFCyAFIAhNDQYgBUH+////B0sNBkHACygCACIEBEBBuAsoAgAiAyAFaiIAIANNDQcgACAESw0HCyAFEAEiACABRw0BDAgLIAUgBmsgB3EiBUH+////B0sNBSAFEAEiASAAKAIAIAAoAgRqRg0EIAEhAAsCQCAAQX9GDQAgCEEwaiAFTQ0AQegLKAIAIgEgCSAFa2pBACABa3EiAUH+////B0sEQCAAIQEMCAsgARABQX9HBEAgASAFaiEFIAAhAQwIC0EAIAVrEAEaDAULIAAiAUF/Rw0GDAQLAAtBACEEDAcLQQAhAQwFCyABQX9HDQILQcQLQcQLKAIAQQRyNgIACyACQf7///8HSw0BIAIQASEBQQAQASEAIAFBf0YNASAAQX9GDQEgACABTQ0BIAAgAWsiBSAIQShqTQ0BC0G4C0G4CygCACAFaiIANgIAQbwLKAIAIABJBEBBvAsgADYCAAsCQAJAAkBBoAgoAgAiBwRAQcgLIQADQCABIAAoAgAiAyAAKAIEIgJqRg0CIAAoAggiAA0ACwwCC0GYCCgCACIAQQAgACABTRtFBEBBmAggATYCAAtBACEAQcwLIAU2AgBByAsgATYCAEGoCEF/NgIAQawIQeALKAIANgIAQdQLQQA2AgADQCAAQQN0IgNBuAhqIANBsAhqIgI2AgAgA0G8CGogAjYCACAAQQFqIgBBIEcNAAtBlAggBUEoayIDQXggAWtBB3FBACABQQhqQQdxGyIAayICNgIAQaAIIAAgAWoiADYCACAAIAJBAXI2AgQgASADakEoNgIEQaQIQfALKAIANgIADAILIAAtAAxBCHENACADIAdLDQAgASAHTQ0AIAAgAiAFajYCBEGgCCAHQXggB2tBB3FBACAHQQhqQQdxGyIAaiICNgIAQZQIQZQIKAIAIAVqIgEgAGsiADYCACACIABBAXI2AgQgASAHakEoNgIEQaQIQfALKAIANgIADAELQZgIKAIAIAFLBEBBmAggATYCAAsgASAFaiECQcgLIQACQAJAAkACQAJAAkADQCACIAAoAgBHBEAgACgCCCIADQEMAgsLIAAtAAxBCHFFDQELQcgLIQADQCAHIAAoAgAiAk8EQCACIAAoAgRqIgQgB0sNAwsgACgCCCEADAALAAsgACABNgIAIAAgACgCBCAFajYCBCABQXggAWtBB3FBACABQQhqQQdxG2oiCSAIQQNyNgIEIAJBeCACa0EHcUEAIAJBCGpBB3EbaiIFIAggCWoiBmshAiAFIAdGBEBBoAggBjYCAEGUCEGUCCgCACACaiIANgIAIAYgAEEBcjYCBAwDCyAFQZwIKAIARgRAQZwIIAY2AgBBkAhBkAgoAgAgAmoiADYCACAGIABBAXI2AgQgACAGaiAANgIADAMLIAUoAgQiAEEDcUEBRgRAIABBeHEhBwJAIABB/wFNBEAgBSgCCCIDIABBA3YiAEEDdEGwCGpGGiADIAUoAgwiAUYEQEGICEGICCgCAEF+IAB3cTYCAAwCCyADIAE2AgwgASADNgIIDAELIAUoAhghCAJAIAUgBSgCDCIBRwRAIAUoAggiACABNgIMIAEgADYCCAwBCwJAIAVBFGoiACgCACIDDQAgBUEQaiIAKAIAIgMNAEEAIQEMAQsDQCAAIQQgAyIBQRRqIgAoAgAiAw0AIAFBEGohACABKAIQIgMNAAsgBEEANgIACyAIRQ0AAkAgBSAFKAIcIgNBAnRBuApqIgAoAgBGBEAgACABNgIAIAENAUGMCEGMCCgCAEF+IAN3cTYCAAwCCyAIQRBBFCAIKAIQIAVGG2ogATYCACABRQ0BCyABIAg2AhggBSgCECIABEAgASAANgIQIAAgATYCGAsgBSgCFCIARQ0AIAEgADYCFCAAIAE2AhgLIAUgB2ohBSACIAdqIQILIAUgBSgCBEF+cTYCBCAGIAJBAXI2AgQgAiAGaiACNgIAIAJB/wFNBEAgAkEDdiIAQQN0QbAIaiECAn9BiAgoAgAiAUEBIAB0IgBxRQRAQYgIIAAgAXI2AgAgAgwBCyACKAIICyEAIAIgBjYCCCAAIAY2AgwgBiACNgIMIAYgADYCCAwDC0EfIQAgAkH///8HTQRAIAJBCHYiACAAQYD+P2pBEHZBCHEiA3QiACAAQYDgH2pBEHZBBHEiAXQiACAAQYCAD2pBEHZBAnEiAHRBD3YgASADciAAcmsiAEEBdCACIABBFWp2QQFxckEcaiEACyAGIAA2AhwgBkIANwIQIABBAnRBuApqIQQCQEGMCCgCACIDQQEgAHQiAXFFBEBBjAggASADcjYCACAEIAY2AgAgBiAENgIYDAELIAJBAEEZIABBAXZrIABBH0YbdCEAIAQoAgAhAQNAIAEiAygCBEF4cSACRg0DIABBHXYhASAAQQF0IQAgAyABQQRxaiIEKAIQIgENAAsgBCAGNgIQIAYgAzYCGAsgBiAGNgIMIAYgBjYCCAwCC0GUCCAFQShrIgNBeCABa0EHcUEAIAFBCGpBB3EbIgBrIgI2AgBBoAggACABaiIANgIAIAAgAkEBcjYCBCABIANqQSg2AgRBpAhB8AsoAgA2AgAgByAEQScgBGtBB3FBACAEQSdrQQdxG2pBL2siACAAIAdBEGpJGyICQRs2AgQgAkHQCykCADcCECACQcgLKQIANwIIQdALIAJBCGo2AgBBzAsgBTYCAEHICyABNgIAQdQLQQA2AgAgAkEYaiEAA0AgAEEHNgIEIABBCGohASAAQQRqIQAgASAESQ0ACyACIAdGDQMgAiACKAIEQX5xNgIEIAcgAiAHayIEQQFyNgIEIAIgBDYCACAEQf8BTQRAIARBA3YiAEEDdEGwCGohAgJ/QYgIKAIAIgFBASAAdCIAcUUEQEGICCAAIAFyNgIAIAIMAQsgAigCCAshACACIAc2AgggACAHNgIMIAcgAjYCDCAHIAA2AggMBAtBHyEAIAdCADcCECAEQf///wdNBEAgBEEIdiIAIABBgP4/akEQdkEIcSICdCIAIABBgOAfakEQdkEEcSIBdCIAIABBgIAPakEQdkECcSIAdEEPdiABIAJyIAByayIAQQF0IAQgAEEVanZBAXFyQRxqIQALIAcgADYCHCAAQQJ0QbgKaiEDAkBBjAgoAgAiAkEBIAB0IgFxRQRAQYwIIAEgAnI2AgAgAyAHNgIAIAcgAzYCGAwBCyAEQQBBGSAAQQF2ayAAQR9GG3QhACADKAIAIQEDQCABIgIoAgRBeHEgBEYNBCAAQR12IQEgAEEBdCEAIAIgAUEEcWoiAygCECIBDQALIAMgBzYCECAHIAI2AhgLIAcgBzYCDCAHIAc2AggMAwsgAygCCCIAIAY2AgwgAyAGNgIIIAZBADYCGCAGIAM2AgwgBiAANgIICyAJQQhqIQAMBQsgAigCCCIAIAc2AgwgAiAHNgIIIAdBADYCGCAHIAI2AgwgByAANgIIC0GUCCgCACIAIAhNDQBBlAggACAIayIBNgIAQaAIQaAIKAIAIgIgCGoiADYCACAAIAFBAXI2AgQgAiAIQQNyNgIEIAJBCGohAAwDC0GECEEwNgIAQQAhAAwCCwJAIAVFDQACQCAEKAIcIgJBAnRBuApqIgAoAgAgBEYEQCAAIAE2AgAgAQ0BQYwIIAlBfiACd3EiCTYCAAwCCyAFQRBBFCAFKAIQIARGG2ogATYCACABRQ0BCyABIAU2AhggBCgCECIABEAgASAANgIQIAAgATYCGAsgBCgCFCIARQ0AIAEgADYCFCAAIAE2AhgLAkAgA0EPTQRAIAQgAyAIaiIAQQNyNgIEIAAgBGoiACAAKAIEQQFyNgIEDAELIAQgCEEDcjYCBCAGIANBAXI2AgQgAyAGaiADNgIAIANB/wFNBEAgA0EDdiIAQQN0QbAIaiECAn9BiAgoAgAiAUEBIAB0IgBxRQRAQYgIIAAgAXI2AgAgAgwBCyACKAIICyEAIAIgBjYCCCAAIAY2AgwgBiACNgIMIAYgADYCCAwBC0EfIQAgA0H///8HTQRAIANBCHYiACAAQYD+P2pBEHZBCHEiAnQiACAAQYDgH2pBEHZBBHEiAXQiACAAQYCAD2pBEHZBAnEiAHRBD3YgASACciAAcmsiAEEBdCADIABBFWp2QQFxckEcaiEACyAGIAA2AhwgBkIANwIQIABBAnRBuApqIQICQAJAIAlBASAAdCIBcUUEQEGMCCABIAlyNgIAIAIgBjYCACAGIAI2AhgMAQsgA0EAQRkgAEEBdmsgAEEfRht0IQAgAigCACEIA0AgCCIBKAIEQXhxIANGDQIgAEEddiECIABBAXQhACABIAJBBHFqIgIoAhAiCA0ACyACIAY2AhAgBiABNgIYCyAGIAY2AgwgBiAGNgIIDAELIAEoAggiACAGNgIMIAEgBjYCCCAGQQA2AhggBiABNgIMIAYgADYCCAsgBEEIaiEADAELAkAgC0UNAAJAIAEoAhwiAkECdEG4CmoiACgCACABRgRAIAAgBDYCACAEDQFBjAggBkF+IAJ3cTYCAAwCCyALQRBBFCALKAIQIAFGG2ogBDYCACAERQ0BCyAEIAs2AhggASgCECIABEAgBCAANgIQIAAgBDYCGAsgASgCFCIARQ0AIAQgADYCFCAAIAQ2AhgLAkAgA0EPTQRAIAEgAyAIaiIAQQNyNgIEIAAgAWoiACAAKAIEQQFyNgIEDAELIAEgCEEDcjYCBCAJIANBAXI2AgQgAyAJaiADNgIAIAoEQCAKQQN2IgBBA3RBsAhqIQRBnAgoAgAhAgJ/QQEgAHQiACAFcUUEQEGICCAAIAVyNgIAIAQMAQsgBCgCCAshACAEIAI2AgggACACNgIMIAIgBDYCDCACIAA2AggLQZwIIAk2AgBBkAggAzYCAAsgAUEIaiEACyAMQRBqJAAgAAsQACMAIABrQXBxIgAkACAACwYAIAAkAAsEACMAC4AJAgh/BH4jAEGQAWsiBiQAIAYgBS0AA0EYdEGAgIAYcSAFLwAAIAUtAAJBEHRycjYCACAGIAUoAANBAnZBg/7/H3E2AgQgBiAFKAAGQQR2Qf+B/x9xNgIIIAYgBSgACUEGdkH//8AfcTYCDCAFLwANIQggBS0ADyEJIAZCADcCFCAGQgA3AhwgBkEANgIkIAYgCCAJQRB0QYCAPHFyNgIQIAYgBSgAEDYCKCAGIAUoABQ2AiwgBiAFKAAYNgIwIAUoABwhBSAGQQA6AEwgBkEANgI4IAYgBTYCNCAGIAEgAhAEIAQEQCAGIAMgBBAECyAGKAI4IgEEQCAGQTxqIgIgAWpBAToAACABQQFqQQ9NBEAgASAGakE9aiEEAkBBDyABayIDRQ0AIAMgBGoiAUEBa0EAOgAAIARBADoAACADQQNJDQAgAUECa0EAOgAAIARBADoAASABQQNrQQA6AAAgBEEAOgACIANBB0kNACABQQRrQQA6AAAgBEEAOgADIANBCUkNACAEQQAgBGtBA3EiAWoiBEEANgIAIAQgAyABa0F8cSIBaiIDQQRrQQA2AgAgAUEJSQ0AIARBADYCCCAEQQA2AgQgA0EIa0EANgIAIANBDGtBADYCACABQRlJDQAgBEEANgIYIARBADYCFCAEQQA2AhAgBEEANgIMIANBEGtBADYCACADQRRrQQA2AgAgA0EYa0EANgIAIANBHGtBADYCACABIARBBHFBGHIiAWsiA0EgSQ0AIAEgBGohAQNAIAFCADcDGCABQgA3AxAgAUIANwMIIAFCADcDACABQSBqIQEgA0EgayIDQR9LDQALCwsgBkEBOgBMIAYgAkEQEAILIAY1AjQhECAGNQIwIREgBjUCLCEOIAAgBjUCKCAGKAIkIAYoAiAgBigCHCAGKAIYIgNBGnZqIgJBGnZqIgFBGnZqIgtBgICAYHIgAUH///8fcSINIAJB////H3EiCCAGKAIUIAtBGnZBBWxqIgFB////H3EiCUEFaiIFQRp2IANB////H3EgAUEadmoiA2oiAUEadmoiAkEadmoiBEEadmoiDEEfdSIHIANxIAEgDEEfdkEBayIDQf///x9xIgpxciIBQRp0IAUgCnEgByAJcXJyrXwiDzwAACAAIA9CGIg8AAMgACAPQhCIPAACIAAgD0IIiDwAASAAIA4gByAIcSACIApxciICQRR0IAFBBnZyrXwgD0IgiHwiDjwABCAAIA5CGIg8AAcgACAOQhCIPAAGIAAgDkIIiDwABSAAIBEgByANcSAEIApxciIBQQ50IAJBDHZyrXwgDkIgiHwiDjwACCAAIA5CGIg8AAsgACAOQhCIPAAKIAAgDkIIiDwACSAAIBAgAyAMcSAHIAtxckEIdCABQRJ2cq18IA5CIIh8Ig48AAwgACAOQhiIPAAPIAAgDkIQiDwADiAAIA5CCIg8AA0gBkIANwIwIAZCADcCKCAGQgA3AiAgBkIANwIYIAZCADcCECAGQgA3AgggBkIANwIAIAZBkAFqJAALpwwBB38CQCAARQ0AIABBCGsiAyAAQQRrKAIAIgFBeHEiAGohBQJAIAFBAXENACABQQNxRQ0BIAMgAygCACIBayIDQZgIKAIASQ0BIAAgAWohACADQZwIKAIARwRAIAFB/wFNBEAgAygCCCICIAFBA3YiBEEDdEGwCGpGGiACIAMoAgwiAUYEQEGICEGICCgCAEF+IAR3cTYCAAwDCyACIAE2AgwgASACNgIIDAILIAMoAhghBgJAIAMgAygCDCIBRwRAIAMoAggiAiABNgIMIAEgAjYCCAwBCwJAIANBFGoiAigCACIEDQAgA0EQaiICKAIAIgQNAEEAIQEMAQsDQCACIQcgBCIBQRRqIgIoAgAiBA0AIAFBEGohAiABKAIQIgQNAAsgB0EANgIACyAGRQ0BAkAgAyADKAIcIgJBAnRBuApqIgQoAgBGBEAgBCABNgIAIAENAUGMCEGMCCgCAEF+IAJ3cTYCAAwDCyAGQRBBFCAGKAIQIANGG2ogATYCACABRQ0CCyABIAY2AhggAygCECICBEAgASACNgIQIAIgATYCGAsgAygCFCICRQ0BIAEgAjYCFCACIAE2AhgMAQsgBSgCBCIBQQNxQQNHDQBBkAggADYCACAFIAFBfnE2AgQgAyAAQQFyNgIEIAAgA2ogADYCAA8LIAMgBU8NACAFKAIEIgFBAXFFDQACQCABQQJxRQRAIAVBoAgoAgBGBEBBoAggAzYCAEGUCEGUCCgCACAAaiIANgIAIAMgAEEBcjYCBCADQZwIKAIARw0DQZAIQQA2AgBBnAhBADYCAA8LIAVBnAgoAgBGBEBBnAggAzYCAEGQCEGQCCgCACAAaiIANgIAIAMgAEEBcjYCBCAAIANqIAA2AgAPCyABQXhxIABqIQACQCABQf8BTQRAIAUoAggiAiABQQN2IgRBA3RBsAhqRhogAiAFKAIMIgFGBEBBiAhBiAgoAgBBfiAEd3E2AgAMAgsgAiABNgIMIAEgAjYCCAwBCyAFKAIYIQYCQCAFIAUoAgwiAUcEQCAFKAIIIgJBmAgoAgBJGiACIAE2AgwgASACNgIIDAELAkAgBUEUaiICKAIAIgQNACAFQRBqIgIoAgAiBA0AQQAhAQwBCwNAIAIhByAEIgFBFGoiAigCACIEDQAgAUEQaiECIAEoAhAiBA0ACyAHQQA2AgALIAZFDQACQCAFIAUoAhwiAkECdEG4CmoiBCgCAEYEQCAEIAE2AgAgAQ0BQYwIQYwIKAIAQX4gAndxNgIADAILIAZBEEEUIAYoAhAgBUYbaiABNgIAIAFFDQELIAEgBjYCGCAFKAIQIgIEQCABIAI2AhAgAiABNgIYCyAFKAIUIgJFDQAgASACNgIUIAIgATYCGAsgAyAAQQFyNgIEIAAgA2ogADYCACADQZwIKAIARw0BQZAIIAA2AgAPCyAFIAFBfnE2AgQgAyAAQQFyNgIEIAAgA2ogADYCAAsgAEH/AU0EQCAAQQN2IgFBA3RBsAhqIQACf0GICCgCACICQQEgAXQiAXFFBEBBiAggASACcjYCACAADAELIAAoAggLIQIgACADNgIIIAIgAzYCDCADIAA2AgwgAyACNgIIDwtBHyECIANCADcCECAAQf///wdNBEAgAEEIdiIBIAFBgP4/akEQdkEIcSIBdCICIAJBgOAfakEQdkEEcSICdCIEIARBgIAPakEQdkECcSIEdEEPdiABIAJyIARyayIBQQF0IAAgAUEVanZBAXFyQRxqIQILIAMgAjYCHCACQQJ0QbgKaiEBAkACQAJAQYwIKAIAIgRBASACdCIHcUUEQEGMCCAEIAdyNgIAIAEgAzYCACADIAE2AhgMAQsgAEEAQRkgAkEBdmsgAkEfRht0IQIgASgCACEBA0AgASIEKAIEQXhxIABGDQIgAkEddiEBIAJBAXQhAiAEIAFBBHFqIgdBEGooAgAiAQ0ACyAHIAM2AhAgAyAENgIYCyADIAM2AgwgAyADNgIIDAELIAQoAggiACADNgIMIAQgAzYCCCADQQA2AhggAyAENgIMIAMgADYCCAtBqAhBqAgoAgBBAWsiAEF/IAAbNgIACwsLCQEAQYEICwIGUA==",!fe.startsWith(X)){var se=fe;fe=e.locateFile?e.locateFile(se,l):l+se}function ze(){var z=fe;try{if(z==fe&&C)return new Uint8Array(C);var ue=kn(z);if(ue)return ue;if(g)return g(z);throw"both async and sync fetching of the wasm failed"}catch(xe){H(xe)}}function _t(){if(!C&&(a||c)){if(typeof fetch=="function"&&!fe.startsWith("file://"))return fetch(fe,{credentials:"same-origin"}).then(function(z){if(!z.ok)throw"failed to load wasm binary file at '"+fe+"'";return z.arrayBuffer()}).catch(function(){return ze()});if(h)return new Promise(function(z,ue){h(fe,function(xe){z(new Uint8Array(xe))},ue)})}return Promise.resolve().then(function(){return ze()})}function An(z){for(;0<z.length;){var ue=z.shift();if(typeof ue=="function")ue(e);else{var xe=ue.m;typeof xe=="number"?ue.l===void 0?re.get(xe)():re.get(xe)(ue.l):xe(ue.l===void 0?null:ue.l)}}}var pr=!1,gr=typeof atob=="function"?atob:function(z){var ue="",xe=0;z=z.replace(/[^A-Za-z0-9\+\/=]/g,"");do{var Pe="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(z.charAt(xe++)),je="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(z.charAt(xe++)),Nt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(z.charAt(xe++)),En="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(z.charAt(xe++));Pe=Pe<<2|je>>4,je=(je&15)<<4|Nt>>2;var tn=(Nt&3)<<6|En;ue+=String.fromCharCode(Pe),Nt!==64&&(ue+=String.fromCharCode(je)),En!==64&&(ue+=String.fromCharCode(tn))}while(xe<z.length);return ue};function kn(z){if(z.startsWith(X)){if(z=z.slice(X.length),typeof f=="boolean"&&f){var ue=Buffer.from(z,"base64");ue=new Uint8Array(ue.buffer,ue.byteOffset,ue.byteLength)}else try{var xe=gr(z),Pe=new Uint8Array(xe.length);for(z=0;z<xe.length;++z)Pe[z]=xe.charCodeAt(z);ue=Pe}catch{throw Error("Converting base64 string to bytes failed.")}return ue}}var mr={a:function(z){var ue=U.length;if(z>>>=0,2147483648<z)return!1;for(var xe=1;4>=xe;xe*=2){var Pe=ue*(1+.2/xe);Pe=Math.min(Pe,z+100663296),Pe=Math.max(z,Pe),0<Pe%65536&&(Pe+=65536-Pe%65536);e:{try{F.grow(Math.min(2147483648,Pe)-w.byteLength+65535>>>16),R();var je=1;break e}catch{}je=void 0}if(je)return!0}return!1}};(function(){function z(je){e.asm=je.exports,F=e.asm.b,R(),re=e.asm.j,Y.unshift(e.asm.c),D--,e.monitorRunDependencies&&e.monitorRunDependencies(D),D==0&&(v!==null&&(clearInterval(v),v=null),N&&(je=N,N=null,je()))}function ue(je){z(je.instance)}function xe(je){return _t().then(function(Nt){return WebAssembly.instantiate(Nt,Pe)}).then(je,function(Nt){b("failed to asynchronously prepare wasm: "+Nt),H(Nt)})}var Pe={a:mr};if(D++,e.monitorRunDependencies&&e.monitorRunDependencies(D),e.instantiateWasm)try{return e.instantiateWasm(Pe,z)}catch(je){return b("Module.instantiateWasm callback failed with error: "+je),!1}return(function(){return C||typeof WebAssembly.instantiateStreaming!="function"||fe.startsWith(X)||fe.startsWith("file://")||typeof fetch!="function"?xe(ue):fetch(fe,{credentials:"same-origin"}).then(function(je){return WebAssembly.instantiateStreaming(je,Pe).then(ue,function(Nt){return b("wasm streaming compile failed: "+Nt),b("falling back to ArrayBuffer instantiation"),xe(ue)})})})().catch(s),{}})(),e.___wasm_call_ctors=function(){return(e.___wasm_call_ctors=e.asm.c).apply(null,arguments)},e._poly1305_auth=function(){return(e._poly1305_auth=e.asm.d).apply(null,arguments)};var jr=e.stackSave=function(){return(jr=e.stackSave=e.asm.e).apply(null,arguments)},Mi=e.stackRestore=function(){return(Mi=e.stackRestore=e.asm.f).apply(null,arguments)},Xr=e.stackAlloc=function(){return(Xr=e.stackAlloc=e.asm.g).apply(null,arguments)};e._malloc=function(){return(e._malloc=e.asm.h).apply(null,arguments)},e._free=function(){return(e._free=e.asm.i).apply(null,arguments)},e.cwrap=function(z,ue,xe,Pe){xe=xe||[];var je=xe.every(function(Nt){return Nt==="number"});return ue!=="string"&&je&&!Pe?ee(z):function(){return O(z,ue,xe,arguments)}};var Ar;N=function z(){Ar||Er(),Ar||(N=z)};function Er(){function z(){if(!Ar&&(Ar=!0,e.calledRun=!0,!k)){if(An(Y),r(e),e.onRuntimeInitialized&&e.onRuntimeInitialized(),e.postRun)for(typeof e.postRun=="function"&&(e.postRun=[e.postRun]);e.postRun.length;){var ue=e.postRun.shift();te.unshift(ue)}An(te)}}if(!(0<D)){if(e.preRun)for(typeof e.preRun=="function"&&(e.preRun=[e.preRun]);e.preRun.length;)ce();An(G),0<D||(e.setStatus?(e.setStatus("Running..."),setTimeout(function(){setTimeout(function(){e.setStatus("")},1),z()},1)):z())}}if(e.run=Er,e.preInit)for(typeof e.preInit=="function"&&(e.preInit=[e.preInit]);0<e.preInit.length;)e.preInit.pop()();return Er(),t.ready})})();typeof ts=="object"&&typeof go=="object"?go.exports=po:typeof define=="function"&&define.amd?define([],function(){return po}):typeof ts=="object"&&(ts.createPoly1305=po)});var Qn=at((dE,zc)=>{"use strict";var{createCipheriv:kr,createDecipheriv:ns,createHmac:mo,randomFillSync:sr,timingSafeEqual:Ao}=require("crypto"),{readUInt32BE:oi,writeUInt32BE:rn}=dn(),Wn=Buffer[Symbol.species],Kc=2**32-1,Vc=Buffer.alloc(0),vr=Buffer.alloc(4),rs=new Map,or=35e3,Eo,To,Lo,Uo,Do,Oo,Mo;try{Eo=require("./crypto/build/Release/sshcrypto.node"),{AESGCMCipher:To,ChaChaPolyCipher:Lo,GenericCipher:Uo,AESGCMDecipher:Do,ChaChaPolyDecipher:Oo,GenericDecipher:Mo}=Eo}catch{}var $t=1,fp=(()=>{function n(t,e,r,s,i,o,a){return{sslName:t,blockLen:e,keyLen:r,ivLen:s!==0||a&$t?s:e,authLen:i,discardLen:o,stream:!!(a&$t)}}return{"chacha20-poly1305@openssh.com":n("chacha20",8,64,0,16,0,$t),"aes128-gcm":n("aes-128-gcm",16,16,12,16,0,$t),"aes256-gcm":n("aes-256-gcm",16,32,12,16,0,$t),"aes128-gcm@openssh.com":n("aes-128-gcm",16,16,12,16,0,$t),"aes256-gcm@openssh.com":n("aes-256-gcm",16,32,12,16,0,$t),"aes128-cbc":n("aes-128-cbc",16,16,0,0,0,0),"aes192-cbc":n("aes-192-cbc",16,24,0,0,0,0),"aes256-cbc":n("aes-256-cbc",16,32,0,0,0,0),"rijndael-cbc@lysator.liu.se":n("aes-256-cbc",16,32,0,0,0,0),"3des-cbc":n("des-ede3-cbc",8,24,0,0,0,0),"blowfish-cbc":n("bf-cbc",8,16,0,0,0,0),"idea-cbc":n("idea-cbc",8,16,0,0,0,0),"cast128-cbc":n("cast-cbc",8,16,0,0,0,0),"aes128-ctr":n("aes-128-ctr",16,16,16,0,0,$t),"aes192-ctr":n("aes-192-ctr",16,24,16,0,0,$t),"aes256-ctr":n("aes-256-ctr",16,32,16,0,0,$t),"3des-ctr":n("des-ede3",8,24,8,0,0,$t),"blowfish-ctr":n("bf-ecb",8,16,8,0,0,$t),"cast128-ctr":n("cast5-ecb",8,16,8,0,0,$t),arcfour:n("rc4",8,16,0,0,1536,$t),arcfour128:n("rc4",8,16,0,0,1536,$t),arcfour256:n("rc4",8,32,0,0,1536,$t),arcfour512:n("rc4",8,64,0,0,1536,$t)}})(),lp=(()=>{function n(t,e,r,s){return{sslName:t,len:e,actualLen:r,isETM:s}}return{"hmac-md5":n("md5",16,16,!1),"hmac-md5-96":n("md5",16,12,!1),"hmac-ripemd160":n("ripemd160",20,20,!1),"hmac-sha1":n("sha1",20,20,!1),"hmac-sha1-etm@openssh.com":n("sha1",20,20,!0),"hmac-sha1-96":n("sha1",20,12,!1),"hmac-sha2-256":n("sha256",32,32,!1),"hmac-sha2-256-etm@openssh.com":n("sha256",32,32,!0),"hmac-sha2-256-96":n("sha256",32,12,!1),"hmac-sha2-512":n("sha512",64,64,!1),"hmac-sha2-512-etm@openssh.com":n("sha512",64,64,!0),"hmac-sha2-512-96":n("sha512",64,12,!1)}})(),_o=class{constructor(t,e){this.outSeqno=t,this._onWrite=e,this._dead=!1}free(){this._dead=!0}allocPacket(t){let e=5+t,r=8-(e&7);r<4&&(r+=8),e+=r;let s=Buffer.allocUnsafe(e);return rn(s,e-4,0),s[4]=r,sr(s,5+t,r),s}encrypt(t){this._dead||(this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},Gc=Buffer.alloc(32),jt=Buffer.alloc(16),si,ai,$o,yo=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._encKeyMain=e.cipherKey.slice(0,32),this._encKeyPktLen=e.cipherKey.slice(32),this._dead=!1}free(){this._dead=!0}allocPacket(t){let e=5+t,r=8-(e-4&7);r<4&&(r+=8),e+=r;let s=Buffer.allocUnsafe(e);return rn(s,e-4,0),s[4]=r,sr(s,5+t,r),s}encrypt(t){if(this._dead)return;jt[0]=0,rn(jt,this.outSeqno,12);let e=kr("chacha20",this._encKeyMain,jt).update(Gc),r=kr("chacha20",this._encKeyPktLen,jt).update(t.slice(0,4));this._onWrite(r),jt[0]=1;let s=kr("chacha20",this._encKeyMain,jt).update(t.slice(4));this._onWrite(s),$o(ai,r,r.length,s,s.length,e);let i=Buffer.allocUnsafe(16);i.set(new Uint8Array(si.HEAPU8.buffer,ai,16),0),this._onWrite(i),this.outSeqno=this.outSeqno+1>>>0}},bo=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._instance=new Lo(e.cipherKey),this._dead=!1}free(){this._dead=!0,this._instance.free()}allocPacket(t){let e=5+t,r=8-(e-4&7);r<4&&(r+=8),e+=r;let s=Buffer.allocUnsafe(e+16);return rn(s,e-4,0),s[4]=r,sr(s,5+t,r),s}encrypt(t){this._dead||(this._instance.encrypt(t,this.outSeqno),this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},xo=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._encSSLName=e.cipherInfo.sslName,this._encKey=e.cipherKey,this._encIV=e.cipherIV,this._dead=!1}free(){this._dead=!0}allocPacket(t){let e=5+t,r=16-(e-4&15);r<4&&(r+=16),e+=r;let s=Buffer.allocUnsafe(e);return rn(s,e-4,0),s[4]=r,sr(s,5+t,r),s}encrypt(t){if(this._dead)return;let e=kr(this._encSSLName,this._encKey,this._encIV);e.setAutoPadding(!1);let r=t.slice(0,4);e.setAAD(r),this._onWrite(r);let s=e.update(t.slice(4));this._onWrite(s);let i=e.final();i.length&&this._onWrite(i);let o=e.getAuthTag();this._onWrite(o),Yc(this._encIV),this.outSeqno=this.outSeqno+1>>>0}},So=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._instance=new To(e.cipherInfo.sslName,e.cipherKey,e.cipherIV),this._dead=!1}free(){this._dead=!0,this._instance.free()}allocPacket(t){let e=5+t,r=16-(e-4&15);r<4&&(r+=16),e+=r;let s=Buffer.allocUnsafe(e+16);return rn(s,e-4,0),s[4]=r,sr(s,5+t,r),s}encrypt(t){this._dead||(this._instance.encrypt(t),this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},wo=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._encBlockLen=e.cipherInfo.blockLen,this._cipherInstance=kr(e.cipherInfo.sslName,e.cipherKey,e.cipherIV),this._macSSLName=e.macInfo.sslName,this._macKey=e.macKey,this._macActualLen=e.macInfo.actualLen,this._macETM=e.macInfo.isETM,this._aadLen=this._macETM?4:0,this._dead=!1;let r=e.cipherInfo.discardLen;if(r){let s=rs.get(r);s===void 0&&(s=Buffer.alloc(r),rs.set(r,s)),this._cipherInstance.update(s)}}free(){this._dead=!0}allocPacket(t){let e=this._encBlockLen,r=5+t,s=e-(r-this._aadLen&e-1);s<4&&(s+=e),r+=s;let i=Buffer.allocUnsafe(r);return rn(i,r-4,0),i[4]=s,sr(i,5+t,s),i}encrypt(t){if(this._dead)return;let e;if(this._macETM){let s=new Uint8Array(t.buffer,t.byteOffset,4),i=this._cipherInstance.update(new Uint8Array(t.buffer,t.byteOffset+4,t.length-4));this._onWrite(s),this._onWrite(i),e=mo(this._macSSLName,this._macKey),rn(vr,this.outSeqno,0),e.update(vr),e.update(s),e.update(i)}else{let s=this._cipherInstance.update(t);this._onWrite(s),e=mo(this._macSSLName,this._macKey),rn(vr,this.outSeqno,0),e.update(vr),e.update(t)}let r=e.digest();r.length>this._macActualLen&&(r=r.slice(0,this._macActualLen)),this._onWrite(r),this.outSeqno=this.outSeqno+1>>>0}},Io=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._encBlockLen=e.cipherInfo.blockLen,this._macLen=e.macInfo.len,this._macActualLen=e.macInfo.actualLen,this._aadLen=e.macInfo.isETM?4:0,this._instance=new Uo(e.cipherInfo.sslName,e.cipherKey,e.cipherIV,e.macInfo.sslName,e.macKey,e.macInfo.isETM),this._dead=!1}free(){this._dead=!0,this._instance.free()}allocPacket(t){let e=this._encBlockLen,r=5+t,s=e-(r-this._aadLen&e-1);s<4&&(s+=e),r+=s;let i=Buffer.allocUnsafe(r+this._macLen);return rn(i,r-4,0),i[4]=s,sr(i,5+t,s),i}encrypt(t){this._dead||(this._instance.encrypt(t,this.outSeqno),this._macActualLen<this._macLen&&(t=new Wn(t.buffer,t.byteOffset,t.length-(this._macLen-this._macActualLen))),this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},Co=class{constructor(t,e){this.inSeqno=t,this._onPayload=e,this._len=0,this._lenBytes=0,this._packet=null,this._packetPos=0}free(){}decrypt(t,e,r){for(;e<r;){if(this._lenBytes<4){let i=Math.min(4-this._lenBytes,r-e);for(this._lenBytes+=i;i--;)this._len=(this._len<<8)+t[e++];if(this._lenBytes<4)return;if(this._len>or||this._len<8||(4+this._len&7)!==0)throw new Error("Bad packet length");if(e>=r)return}if(this._packetPos<this._len){let i=Math.min(this._len-this._packetPos,r-e),o;if(e!==0||i!==r?o=new Uint8Array(t.buffer,t.byteOffset+e,i):o=t,i===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._packetPos)),e+=i,this._packetPos+=i,this._packetPos<this._len)return}let s=this._packet?new Wn(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1):Vc;this.inSeqno=this.inSeqno+1>>>0,this._len=0,this._lenBytes=0,this._packet=null,this._packetPos=0;{let i=this._onPayload(s);if(i!==void 0)return i===!1?e:i}}}},vo=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._decKeyMain=e.decipherKey.slice(0,32),this._decKeyPktLen=e.decipherKey.slice(32),this._len=0,this._lenBuf=Buffer.alloc(4),this._lenPos=0,this._packet=null,this._pktLen=0,this._mac=Buffer.allocUnsafe(16),this._calcMac=Buffer.allocUnsafe(16),this._macPos=0}free(){}decrypt(t,e,r){for(;e<r;){if(this._lenPos<4){let a=Math.min(4-this._lenPos,r-e);for(;a--;)this._lenBuf[this._lenPos++]=t[e++];if(this._lenPos<4)return;jt[0]=0,rn(jt,this.inSeqno,12);let c=ns("chacha20",this._decKeyPktLen,jt).update(this._lenBuf);if(this._len=oi(c,0),this._len>or||this._len<8||(this._len&7)!==0)throw new Error("Bad packet length")}if(this._pktLen<this._len){if(e>=r)return;let a=Math.min(this._len-this._pktLen,r-e),c;if(e!==0||a!==r?c=new Uint8Array(t.buffer,t.byteOffset+e,a):c=t,a===this._len?this._packet=c:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(c,this._pktLen)),e+=a,this._pktLen+=a,this._pktLen<this._len||e>=r)return}{let a=Math.min(16-this._macPos,r-e);if(e!==0||a!==r?this._mac.set(new Uint8Array(t.buffer,t.byteOffset+e,a),this._macPos):this._mac.set(t,this._macPos),e+=a,this._macPos+=a,this._macPos<16)return}jt[0]=0,rn(jt,this.inSeqno,12);let s=kr("chacha20",this._decKeyMain,jt).update(Gc);if($o(ai,this._lenBuf,4,this._packet,this._packet.length,s),this._calcMac.set(new Uint8Array(si.HEAPU8.buffer,ai,16),0),!Ao(this._calcMac,this._mac))throw new Error("Invalid MAC");jt[0]=1;let i=ns("chacha20",this._decKeyMain,jt).update(this._packet),o=new Wn(i.buffer,i.byteOffset+1,i.length-i[0]-1);this.inSeqno=this.inSeqno+1>>>0,this._len=0,this._lenPos=0,this._packet=null,this._pktLen=0,this._macPos=0;{let a=this._onPayload(o);if(a!==void 0)return a===!1?e:a}}}},ko=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._instance=new Oo(e.decipherKey),this._len=0,this._lenBuf=Buffer.alloc(4),this._lenPos=0,this._packet=null,this._pktLen=0,this._mac=Buffer.allocUnsafe(16),this._macPos=0}free(){this._instance.free()}decrypt(t,e,r){for(;e<r;){if(this._lenPos<4){let i=Math.min(4-this._lenPos,r-e);for(;i--;)this._lenBuf[this._lenPos++]=t[e++];if(this._lenPos<4)return;if(this._len=this._instance.decryptLen(this._lenBuf,this.inSeqno),this._len>or||this._len<8||(this._len&7)!==0)throw new Error("Bad packet length");if(e>=r)return}if(this._pktLen<this._len){let i=Math.min(this._len-this._pktLen,r-e),o;if(e!==0||i!==r?o=new Uint8Array(t.buffer,t.byteOffset+e,i):o=t,i===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._pktLen)),e+=i,this._pktLen+=i,this._pktLen<this._len||e>=r)return}{let i=Math.min(16-this._macPos,r-e);if(e!==0||i!==r?this._mac.set(new Uint8Array(t.buffer,t.byteOffset+e,i),this._macPos):this._mac.set(t,this._macPos),e+=i,this._macPos+=i,this._macPos<16)return}this._instance.decrypt(this._packet,this._mac,this.inSeqno);let s=new Wn(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1);this.inSeqno=this.inSeqno+1>>>0,this._len=0,this._lenPos=0,this._packet=null,this._pktLen=0,this._macPos=0;{let i=this._onPayload(s);if(i!==void 0)return i===!1?e:i}}}},Bo=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._decipherInstance=null,this._decipherSSLName=e.decipherInfo.sslName,this._decipherKey=e.decipherKey,this._decipherIV=e.decipherIV,this._len=0,this._lenBytes=0,this._packet=null,this._packetPos=0,this._pktLen=0,this._tag=Buffer.allocUnsafe(16),this._tagPos=0}free(){}decrypt(t,e,r){for(;e<r;){if(this._lenBytes<4){let i=Math.min(4-this._lenBytes,r-e);for(this._lenBytes+=i;i--;)this._len=(this._len<<8)+t[e++];if(this._lenBytes<4)return;if(this._len+20>or||this._len<16||(this._len&15)!==0)throw new Error("Bad packet length");this._decipherInstance=ns(this._decipherSSLName,this._decipherKey,this._decipherIV),this._decipherInstance.setAutoPadding(!1),this._decipherInstance.setAAD(up(this._len))}if(this._pktLen<this._len){if(e>=r)return;let i=Math.min(this._len-this._pktLen,r-e),o;if(e!==0||i!==r?o=this._decipherInstance.update(new Uint8Array(t.buffer,t.byteOffset+e,i)):o=this._decipherInstance.update(t),o.length&&(i===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._packetPos)),this._packetPos+=o.length),e+=i,this._pktLen+=i,this._pktLen<this._len||e>=r)return}{let i=Math.min(16-this._tagPos,r-e);if(e!==0||i!==r?this._tag.set(new Uint8Array(t.buffer,t.byteOffset+e,i),this._tagPos):this._tag.set(t,this._tagPos),e+=i,this._tagPos+=i,this._tagPos<16)return}{this._decipherInstance.setAuthTag(this._tag);let i=this._decipherInstance.final();i.length&&(this._packet?this._packet.set(i,this._packetPos):this._packet=i)}let s=this._packet?new Wn(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1):Vc;this.inSeqno=this.inSeqno+1>>>0,Yc(this._decipherIV),this._len=0,this._lenBytes=0,this._packet=null,this._packetPos=0,this._pktLen=0,this._tagPos=0;{let i=this._onPayload(s);if(i!==void 0)return i===!1?e:i}}}},Ro=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._instance=new Do(e.decipherInfo.sslName,e.decipherKey,e.decipherIV),this._len=0,this._lenBytes=0,this._packet=null,this._pktLen=0,this._tag=Buffer.allocUnsafe(16),this._tagPos=0}free(){}decrypt(t,e,r){for(;e<r;){if(this._lenBytes<4){let i=Math.min(4-this._lenBytes,r-e);for(this._lenBytes+=i;i--;)this._len=(this._len<<8)+t[e++];if(this._lenBytes<4)return;if(this._len+20>or||this._len<16||(this._len&15)!==0)throw new Error(`Bad packet length: ${this._len}`)}if(this._pktLen<this._len){if(e>=r)return;let i=Math.min(this._len-this._pktLen,r-e),o;if(e!==0||i!==r?o=new Uint8Array(t.buffer,t.byteOffset+e,i):o=t,i===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._pktLen)),e+=i,this._pktLen+=i,this._pktLen<this._len||e>=r)return}{let i=Math.min(16-this._tagPos,r-e);if(e!==0||i!==r?this._tag.set(new Uint8Array(t.buffer,t.byteOffset+e,i),this._tagPos):this._tag.set(t,this._tagPos),e+=i,this._tagPos+=i,this._tagPos<16)return}this._instance.decrypt(this._packet,this._len,this._tag);let s=new Wn(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1);this.inSeqno=this.inSeqno+1>>>0,this._len=0,this._lenBytes=0,this._packet=null,this._pktLen=0,this._tagPos=0;{let i=this._onPayload(s);if(i!==void 0)return i===!1?e:i}}}},No=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._decipherInstance=ns(e.decipherInfo.sslName,e.decipherKey,e.decipherIV),this._decipherInstance.setAutoPadding(!1),this._block=Buffer.allocUnsafe(e.macInfo.isETM?4:e.decipherInfo.blockLen),this._blockSize=e.decipherInfo.blockLen,this._blockPos=0,this._len=0,this._packet=null,this._packetPos=0,this._pktLen=0,this._mac=Buffer.allocUnsafe(e.macInfo.actualLen),this._macPos=0,this._macSSLName=e.macInfo.sslName,this._macKey=e.macKey,this._macActualLen=e.macInfo.actualLen,this._macETM=e.macInfo.isETM,this._macInstance=null;let r=e.decipherInfo.discardLen;if(r){let s=rs.get(r);s===void 0&&(s=Buffer.alloc(r),rs.set(r,s)),this._decipherInstance.update(s)}}free(){}decrypt(t,e,r){for(;e<r;){if(this._blockPos<this._block.length){let o=Math.min(this._block.length-this._blockPos,r-e);if(e!==0||o!==r||o<t.length?this._block.set(new Uint8Array(t.buffer,t.byteOffset+e,o),this._blockPos):this._block.set(t,this._blockPos),e+=o,this._blockPos+=o,this._blockPos<this._block.length)return;let a,c;if(this._macETM?this._len=c=oi(this._block,0):(a=this._decipherInstance.update(this._block),this._len=oi(a,0),c=4+this._len-this._blockSize),this._len>or||this._len<5||(c&this._blockSize-1)!==0)throw new Error("Bad packet length");if(this._macInstance=mo(this._macSSLName,this._macKey),rn(vr,this.inSeqno,0),this._macInstance.update(vr),this._macETM?this._macInstance.update(this._block):(this._macInstance.update(new Uint8Array(a.buffer,a.byteOffset,4)),this._pktLen=a.length-4,this._packetPos=this._pktLen,this._packet=Buffer.allocUnsafe(this._len),this._packet.set(new Uint8Array(a.buffer,a.byteOffset+4,this._packetPos),0)),e>=r)return}if(this._pktLen<this._len){let o=Math.min(this._len-this._pktLen,r-e),a;e!==0||o!==r?a=new Uint8Array(t.buffer,t.byteOffset+e,o):a=t,this._macETM&&this._macInstance.update(a);let c=this._decipherInstance.update(a);if(c.length&&(o===this._len?this._packet=c:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(c,this._packetPos)),this._packetPos+=c.length),e+=o,this._pktLen+=o,this._pktLen<this._len||e>=r)return}{let o=Math.min(this._macActualLen-this._macPos,r-e);if(e!==0||o!==r?this._mac.set(new Uint8Array(t.buffer,t.byteOffset+e,o),this._macPos):this._mac.set(t,this._macPos),e+=o,this._macPos+=o,this._macPos<this._macActualLen)return}this._macETM||this._macInstance.update(this._packet);let s=this._macInstance.digest();if(this._macActualLen<s.length&&(s=new Uint8Array(s.buffer,s.byteOffset,this._macActualLen)),!dp(s,this._mac))throw new Error("Invalid MAC");let i=new Wn(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1);this.inSeqno=this.inSeqno+1>>>0,this._blockPos=0,this._len=0,this._packet=null,this._packetPos=0,this._pktLen=0,this._macPos=0,this._macInstance=null;{let o=this._onPayload(i);if(o!==void 0)return o===!1?e:o}}}},Po=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._instance=new Mo(e.decipherInfo.sslName,e.decipherKey,e.decipherIV,e.macInfo.sslName,e.macKey,e.macInfo.isETM,e.macInfo.actualLen),this._block=Buffer.allocUnsafe(e.macInfo.isETM||e.decipherInfo.stream?4:e.decipherInfo.blockLen),this._blockPos=0,this._len=0,this._packet=null,this._pktLen=0,this._mac=Buffer.allocUnsafe(e.macInfo.actualLen),this._macPos=0,this._macActualLen=e.macInfo.actualLen,this._macETM=e.macInfo.isETM}free(){this._instance.free()}decrypt(t,e,r){for(;e<r;){if(this._blockPos<this._block.length){let i=Math.min(this._block.length-this._blockPos,r-e);if(e!==0||i!==r||i<t.length?this._block.set(new Uint8Array(t.buffer,t.byteOffset+e,i),this._blockPos):this._block.set(t,this._blockPos),e+=i,this._blockPos+=i,this._blockPos<this._block.length)return;let o;if(this._macETM?this._len=o=oi(this._block,0):(this._instance.decryptBlock(this._block),this._len=oi(this._block,0),o=4+this._len-this._block.length),this._len>or||this._len<5||(o&this._block.length-1)!==0)throw new Error("Bad packet length");if(this._macETM||(this._pktLen=this._block.length-4,this._pktLen&&(this._packet=Buffer.allocUnsafe(this._len),this._packet.set(new Uint8Array(this._block.buffer,this._block.byteOffset+4,this._pktLen),0))),e>=r)return}if(this._pktLen<this._len){let i=Math.min(this._len-this._pktLen,r-e),o;if(e!==0||i!==r?o=new Uint8Array(t.buffer,t.byteOffset+e,i):o=t,i===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._pktLen)),e+=i,this._pktLen+=i,this._pktLen<this._len||e>=r)return}{let i=Math.min(this._macActualLen-this._macPos,r-e);if(e!==0||i!==r?this._mac.set(new Uint8Array(t.buffer,t.byteOffset+e,i),this._macPos):this._mac.set(t,this._macPos),e+=i,this._macPos+=i,this._macPos<this._macActualLen)return}this._instance.decrypt(this._packet,this.inSeqno,this._block,this._mac);let s=new Wn(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1);this.inSeqno=this.inSeqno+1>>>0,this._blockPos=0,this._len=0,this._packet=null,this._pktLen=0,this._macPos=0,this._macInstance=null;{let i=this._onPayload(s);if(i!==void 0)return i===!1?e:i}}}};function Yc(n){++n[11]>>>8&&++n[10]>>>8&&++n[9]>>>8&&++n[8]>>>8&&++n[7]>>>8&&++n[6]>>>8&&++n[5]>>>8&&++n[4]>>>8}var up=(()=>{let n=Buffer.alloc(4);return t=>(n[0]=t>>>24,n[1]=t>>>16,n[2]=t>>>8,n[3]=t,n)})();function dp(n,t){return n.length!==t.length?(Ao(n,n),!1):Ao(n,t)}function hp(n){if(typeof n!="object"||n===null)throw new Error("Invalid config");if(typeof n.outbound!="object"||n.outbound===null)throw new Error("Invalid outbound");let t=n.outbound;if(typeof t.onWrite!="function")throw new Error("Invalid outbound.onWrite");if(typeof t.cipherInfo!="object"||t.cipherInfo===null)throw new Error("Invalid outbound.cipherInfo");if(!Buffer.isBuffer(t.cipherKey)||t.cipherKey.length!==t.cipherInfo.keyLen)throw new Error("Invalid outbound.cipherKey");if(t.cipherInfo.ivLen&&(!Buffer.isBuffer(t.cipherIV)||t.cipherIV.length!==t.cipherInfo.ivLen))throw new Error("Invalid outbound.cipherIV");if(typeof t.seqno!="number"||t.seqno<0||t.seqno>Kc)throw new Error("Invalid outbound.seqno");let e=!!t.forceNative;switch(t.cipherInfo.sslName){case"aes-128-gcm":case"aes-256-gcm":return To&&!e?new So(n):new xo(n);case"chacha20":return Lo&&!e?new bo(n):new yo(n);default:{if(typeof t.macInfo!="object"||t.macInfo===null)throw new Error("Invalid outbound.macInfo");if(!Buffer.isBuffer(t.macKey)||t.macKey.length!==t.macInfo.len)throw new Error("Invalid outbound.macKey");return Uo&&!e?new Io(n):new wo(n)}}}function pp(n){if(typeof n!="object"||n===null)throw new Error("Invalid config");if(typeof n.inbound!="object"||n.inbound===null)throw new Error("Invalid inbound");let t=n.inbound;if(typeof t.onPayload!="function")throw new Error("Invalid inbound.onPayload");if(typeof t.decipherInfo!="object"||t.decipherInfo===null)throw new Error("Invalid inbound.decipherInfo");if(!Buffer.isBuffer(t.decipherKey)||t.decipherKey.length!==t.decipherInfo.keyLen)throw new Error("Invalid inbound.decipherKey");if(t.decipherInfo.ivLen&&(!Buffer.isBuffer(t.decipherIV)||t.decipherIV.length!==t.decipherInfo.ivLen))throw new Error("Invalid inbound.decipherIV");if(typeof t.seqno!="number"||t.seqno<0||t.seqno>Kc)throw new Error("Invalid inbound.seqno");let e=!!t.forceNative;switch(t.decipherInfo.sslName){case"aes-128-gcm":case"aes-256-gcm":return Do&&!e?new Ro(n):new Bo(n);case"chacha20":return Oo&&!e?new ko(n):new vo(n);default:{if(typeof t.macInfo!="object"||t.macInfo===null)throw new Error("Invalid inbound.macInfo");if(!Buffer.isBuffer(t.macKey)||t.macKey.length!==t.macInfo.len)throw new Error("Invalid inbound.macKey");return Mo&&!e?new Po(n):new No(n)}}}zc.exports={CIPHER_INFO:fp,MAC_INFO:lp,bindingAvailable:!!Eo,init:new Promise(async(n,t)=>{try{si=await qc()(),ai=si._malloc(16),$o=si.cwrap("poly1305_auth",null,["number","array","number","array","number","array"])}catch(e){return t(e)}n()}),NullCipher:_o,createCipher:hp,NullDecipher:Co,createDecipher:pp}});var Kn=at((hE,of)=>{"use strict";var{createDecipheriv:Ho,createECDH:gp,createHash:fi,createHmac:mp,createSign:Ap,createVerify:Ep,getCiphers:_p,sign:jc,verify:Xc}=require("crypto"),yp=_p(),{Ber:Be}=ni(),bp=fo().pbkdf,{CIPHER_INFO:li}=Qn(),{eddsaSupported:Qo,SUPPORTED_CIPHER:xp}=Pn(),{bufferSlice:ar,makeBufferParser:Sp,readString:ve,readUInt32BE:ci,writeUInt32BE:Dt}=dn(),Tn=Symbol("Hash Algorithm"),hn=Symbol("Private key PEM"),_n=Symbol("Public key PEM"),qn=Symbol("Public key SSH"),Br=Symbol("Decrypted Key"),Fo=Object.create(null);{let n=Object.keys(li);for(let t=0;t<n.length;++t){let e=li[n[t]].sslName;!e||Fo[e]||(Fo[e]=li[n[t]])}}var is=Sp();function pn(n,t){t=t.base64Slice(0,t.length);let e=t.replace(/.{64}/g,`$&
|
|
4
4
|
`);return t.length&63&&(e+=`
|
|
5
5
|
`),`-----BEGIN ${n} KEY-----
|
|
6
|
-
${e}-----END ${n} KEY-----`}function _i(n,t){let e=Buffer.allocUnsafe(n.length+t.length);return e.set(n,0),e.set(t,n.length),e}function la(n,t){let e=n.length,r=n._pos||0;for(let s=0;s<t;++s){let i=e-r;if(r>=e||i<4)return!1;let o=mi(n,r);if(i<4+o)return!1;r+=4+o}return n._pos=r,!0}function yi(n,t){let e=new Re.Writer;return e.startSequence(),e.startSequence(),e.writeOID("1.2.840.113549.1.1.1"),e.writeNull(),e.endSequence(),e.startSequence(Re.BitString),e.writeByte(0),e.startSequence(),e.writeBuffer(n,Re.Integer),e.writeBuffer(t,Re.Integer),e.endSequence(),e.endSequence(),e.endSequence(),gn("PUBLIC",e.buffer)}function bi(n,t){let e=Buffer.allocUnsafe(15+t.length+4+n.length);Ot(e,7,0),e.utf8Write("ssh-rsa",4,7);let r=11;return Ot(e,t.length,r),e.set(t,r+=4),Ot(e,n.length,r+=t.length),e.set(n,r+4),e}var Lu=(()=>{function n(r,s,i,o,a,c,f,l){let u=new Re.Writer;return u.startSequence(),u.writeInt(0,Re.Integer),u.writeBuffer(r,Re.Integer),u.writeBuffer(s,Re.Integer),u.writeBuffer(i,Re.Integer),u.writeBuffer(o,Re.Integer),u.writeBuffer(a,Re.Integer),u.writeBuffer(c,Re.Integer),u.writeBuffer(f,Re.Integer),u.writeBuffer(l,Re.Integer),u.endSequence(),u.buffer}function t(r){return BigInt(`0x${r.hexSlice(0,r.length)}`)}function e(r){let s=r.toString(16);if((s.length&1)!==0)s=`0${s}`;else{let i=s.charCodeAt(0);(i===56||i===57||i>=97&&i<=102)&&(s=`00${s}`)}return Buffer.from(s,"hex")}return function(s,i,o,a,c,f){let l=t(o),u=e(l%(t(c)-1n)),h=e(l%(t(f)-1n));return gn("RSA PRIVATE",n(s,i,o,c,f,u,h,a))}})();function xi(n,t,e,r){let s=new Re.Writer;return s.startSequence(),s.startSequence(),s.writeOID("1.2.840.10040.4.1"),s.startSequence(),s.writeBuffer(n,Re.Integer),s.writeBuffer(t,Re.Integer),s.writeBuffer(e,Re.Integer),s.endSequence(),s.endSequence(),s.startSequence(Re.BitString),s.writeByte(0),s.writeBuffer(r,Re.Integer),s.endSequence(),s.endSequence(),gn("PUBLIC",s.buffer)}function Si(n,t,e,r){let s=Buffer.allocUnsafe(15+n.length+4+t.length+4+e.length+4+r.length);Ot(s,7,0),s.utf8Write("ssh-dss",4,7);let i=11;return Ot(s,n.length,i),s.set(n,i+=4),Ot(s,t.length,i+=n.length),s.set(t,i+=4),Ot(s,e.length,i+=t.length),s.set(e,i+=4),Ot(s,r.length,i+=e.length),s.set(r,i+4),s}function Uu(n,t,e,r,s){let i=new Re.Writer;return i.startSequence(),i.writeInt(0,Re.Integer),i.writeBuffer(n,Re.Integer),i.writeBuffer(t,Re.Integer),i.writeBuffer(e,Re.Integer),i.writeBuffer(r,Re.Integer),i.writeBuffer(s,Re.Integer),i.endSequence(),gn("DSA PRIVATE",i.buffer)}function Du(n){let t=new Re.Writer;return t.startSequence(),t.startSequence(),t.writeOID("1.3.101.112"),t.endSequence(),t.startSequence(Re.BitString),t.writeByte(0),t._ensure(n.length),t._buf.set(n,t._offset),t._offset+=n.length,t.endSequence(),t.endSequence(),gn("PUBLIC",t.buffer)}function Ou(n){let t=Buffer.allocUnsafe(19+n.length);return Ot(t,11,0),t.utf8Write("ssh-ed25519",4,11),Ot(t,n.length,15),t.set(n,19),t}function Og(n){let t=new Re.Writer;return t.startSequence(),t.writeInt(0,Re.Integer),t.startSequence(),t.writeOID("1.3.101.112"),t.endSequence(),t.startSequence(Re.OctetString),t.writeBuffer(n,Re.OctetString),t.endSequence(),t.endSequence(),gn("PRIVATE",t.buffer)}function ua(n,t){let e=new Re.Writer;return e.startSequence(),e.startSequence(),e.writeOID("1.2.840.10045.2.1"),e.writeOID(n),e.endSequence(),e.startSequence(Re.BitString),e.writeByte(0),e._ensure(t.length),e._buf.set(t,e._offset),e._offset+=t.length,e.endSequence(),e.endSequence(),gn("PUBLIC",e.buffer)}function da(n,t){let e;switch(n){case"1.2.840.10045.3.1.7":e="nistp256";break;case"1.3.132.0.34":e="nistp384";break;case"1.3.132.0.35":e="nistp521";break;default:return}let r=Buffer.allocUnsafe(39+t.length);return Ot(r,19,0),r.utf8Write(`ecdsa-sha2-${e}`,4,19),Ot(r,8,23),r.utf8Write(e,27,8),Ot(r,t.length,35),r.set(t,39),r}function Mg(n,t,e){let r=new Re.Writer;return r.startSequence(),r.writeInt(1,Re.Integer),r.writeBuffer(e,Re.OctetString),r.startSequence(160),r.writeOID(n),r.endSequence(),r.startSequence(161),r.startSequence(Re.BitString),r.writeByte(0),r._ensure(t.length),r._buf.set(t,r._offset),r._offset+=t.length,r.endSequence(),r.endSequence(),r.endSequence(),gn("EC PRIVATE",r.buffer)}function $g(n,t){let e=kg(n);return e.setPrivateKey(t),e.getPublicKey()}var wi={sign:typeof Pu=="function"?function(t,e){let r=this[pn];if(r===null)return new Error("No private key available");(!e||typeof e!="string")&&(e=this[Un]);try{return Pu(e,t,r)}catch(s){return s}}:function(t,e){let r=this[pn];if(r===null)return new Error("No private key available");(!e||typeof e!="string")&&(e=this[Un]);let s=Rg(e);s.update(t);try{return s.sign(r)}catch(i){return i}},verify:typeof Tu=="function"?function(t,e,r){let s=this[In];if(s===null)return new Error("No public key available");(!r||typeof r!="string")&&(r=this[Un]);try{return Tu(r,t,s,e)}catch(i){return i}}:function(t,e,r){let s=this[In];if(s===null)return new Error("No public key available");(!r||typeof r!="string")&&(r=this[Un]);let i=Ng(r);i.update(t);try{return i.verify(s,e)}catch(o){return o}},isPrivateKey:function(){return this[pn]!==null},getPrivatePEM:function(){return this[pn]},getPublicPEM:function(){return this[In]},getPublicSSH:function(){return this[Gn]},equals:function(t){let e=Fu(t);return e instanceof Error?!1:this.type===e.type&&this[pn]===e[pn]&&this[In]===e[In]&&this[Gn].equals(e[Gn])}};function xs(n,t,e,r,s,i,o){this.type=n,this.comment=t,this[pn]=e,this[In]=r,this[Gn]=s,this[Un]=i,this[Or]=o}xs.prototype=wi;{let t=function(e,r,s){let i=[];if(e.length<8)return new Error("Malformed OpenSSH private key");let o=mi(e,0),a=mi(e,4);if(o!==a)return s?new Error("OpenSSH key integrity check failed -- bad passphrase?"):new Error("OpenSSH key integrity check failed");e._pos=8;let c,f;for(c=0;c<r;++c){let u,h,g,y,_=ve(e,e._pos,!0);if(_===void 0)return new Error("Malformed OpenSSH private key");switch(_){case"ssh-rsa":{let C=ve(e,e._pos);if(C===void 0)return new Error("Malformed OpenSSH private key");let L=ve(e,e._pos);if(L===void 0)return new Error("Malformed OpenSSH private key");let F=ve(e,e._pos);if(F===void 0)return new Error("Malformed OpenSSH private key");let k=ve(e,e._pos);if(k===void 0)return new Error("Malformed OpenSSH private key");let K=ve(e,e._pos);if(K===void 0)return new Error("Malformed OpenSSH private key");let ee=ve(e,e._pos);if(ee===void 0)return new Error("Malformed OpenSSH private key");g=yi(C,L),y=bi(C,L),h=Lu(C,L,F,k,K,ee),u="sha1";break}case"ssh-dss":{let C=ve(e,e._pos);if(C===void 0)return new Error("Malformed OpenSSH private key");let L=ve(e,e._pos);if(L===void 0)return new Error("Malformed OpenSSH private key");let F=ve(e,e._pos);if(F===void 0)return new Error("Malformed OpenSSH private key");let k=ve(e,e._pos);if(k===void 0)return new Error("Malformed OpenSSH private key");let K=ve(e,e._pos);if(K===void 0)return new Error("Malformed OpenSSH private key");g=xi(C,L,F,k),y=Si(C,L,F,k),h=Uu(C,L,F,k,K),u="sha1";break}case"ssh-ed25519":{if(!fa)return new Error(`Unsupported OpenSSH private key type: ${_}`);let C=ve(e,e._pos);if(C===void 0||C.length!==32)return new Error("Malformed OpenSSH private key");let L=ve(e,e._pos);if(L===void 0||L.length!==64)return new Error("Malformed OpenSSH private key");g=Du(C),y=Ou(C),h=Og(dr(L,0,32)),u=null;break}case"ecdsa-sha2-nistp256":u="sha256",f="1.2.840.10045.3.1.7";case"ecdsa-sha2-nistp384":u===void 0&&(u="sha384",f="1.3.132.0.34");case"ecdsa-sha2-nistp521":{if(u===void 0&&(u="sha512",f="1.3.132.0.35"),!la(e,1))return new Error("Malformed OpenSSH private key");let C=ve(e,e._pos);if(C===void 0)return new Error("Malformed OpenSSH private key");let L=ve(e,e._pos);if(L===void 0)return new Error("Malformed OpenSSH private key");g=ua(f,C),y=da(f,C),h=Mg(f,C,L);break}default:return new Error(`Unsupported OpenSSH private key type: ${_}`)}let b=ve(e,e._pos,!0);if(b===void 0)return new Error("Malformed OpenSSH private key");i.push(new xs(_,b,h,g,y,u,s))}let l=0;for(c=e._pos;c<e.length;++c)if(e[c]!==++l%255)return new Error("Malformed OpenSSH private key");return i},n=/^-----BEGIN OPENSSH PRIVATE KEY-----(?:\r\n|\n)([\s\S]+)(?:\r\n|\n)-----END OPENSSH PRIVATE KEY-----$/;xs.parse=(e,r)=>{let s=n.exec(e);if(s===null)return null;let i,o=Buffer.from(s[1],"base64");if(o.length<31)return new Error("Malformed OpenSSH private key");let a=o.utf8Slice(0,15);if(a!=="openssh-key-v1\0")return new Error(`Unsupported OpenSSH key magic: ${a}`);let c=ve(o,15,!0);if(c===void 0)return new Error("Malformed OpenSSH private key");if(c!=="none"&&Ug.indexOf(c)===-1)return new Error(`Unsupported cipher for OpenSSH key: ${c}`);let f=ve(o,o._pos,!0);if(f===void 0)return new Error("Malformed OpenSSH private key");if(f!=="none"){if(c==="none")return new Error("Malformed OpenSSH private key");if(f!=="bcrypt")return new Error(`Unsupported kdf name for OpenSSH key: ${f}`);if(!r)return new Error("Encrypted private OpenSSH key detected, but no passphrase given")}else if(c!=="none")return new Error("Malformed OpenSSH private key");let l,u,h;c!=="none"&&(l=Ei[c]);let g=ve(o,o._pos);if(g===void 0)return new Error("Malformed OpenSSH private key");if(g.length)switch(f){case"none":return new Error("Malformed OpenSSH private key");case"bcrypt":{let _=ve(g,0);if(_===void 0||g._pos+4>g.length)return new Error("Malformed OpenSSH private key");let b=mi(g,g._pos),C=Buffer.allocUnsafe(l.keyLen+l.ivLen);if(Lg(r,r.length,_,_.length,C,C.length,b)!==0)return new Error("Failed to generate information to decrypt key");u=dr(C,0,l.keyLen),h=dr(C,l.keyLen,C.length);break}}else if(f!=="none")return new Error("Malformed OpenSSH private key");if(o._pos+3>=o.length)return new Error("Malformed OpenSSH private key");let y=mi(o,o._pos);if(o._pos+=4,y>0){for(let b=0;b<y;++b){let C=ve(o,o._pos);if(C===void 0)return new Error("Malformed OpenSSH private key");if(ve(C,0,!0)===void 0)return new Error("Malformed OpenSSH private key")}let _=ve(o,o._pos);if(_===void 0)return new Error("Malformed OpenSSH private key");if(u!==void 0){if(_.length<l.blockLen||_.length%l.blockLen!==0)return new Error("Malformed OpenSSH private key");try{let b={authTagLength:l.authLen},C=ca(l.sslName,u,h,b);if(C.setAutoPadding(!1),l.authLen>0){if(o.length-o._pos<l.authLen)return new Error("Malformed OpenSSH private key");C.setAuthTag(dr(o,o._pos,o._pos+=l.authLen))}_=_i(C.update(_),C.final())}catch(b){return b}}if(o._pos!==o.length)return new Error("Malformed OpenSSH private key");i=t(_,y,u!==void 0)}else i=[];return i instanceof Error?i:i[0]}}function Ss(n,t,e,r,s,i,o){this.type=n,this.comment=t,this[pn]=e,this[In]=r,this[Gn]=s,this[Un]=i,this[Or]=o}Ss.prototype=wi;{let n=/^-----BEGIN (RSA|DSA|EC) PRIVATE KEY-----(?:\r\n|\n)((?:[^:]+:\s*[\S].*(?:\r\n|\n))*)([\s\S]+)(?:\r\n|\n)-----END (RSA|DSA|EC) PRIVATE KEY-----$/;Ss.parse=(t,e)=>{let r=n.exec(t);if(r===null)return null;let s=Buffer.from(r[3],"base64"),i=r[2],o=!1;if(i!==void 0){i=i.split(/\r\n|\n/g);for(let y=0;y<i.length;++y){let _=i[y],b=_.indexOf(":");if(_.slice(0,b)==="DEK-Info"){let C=_.slice(b+2);if(b=C.indexOf(","),b===-1)continue;let L=C.slice(0,b).toLowerCase();if(Tg.indexOf(L)===-1)return new Error(`Cipher (${L}) not supported for encrypted OpenSSH private key`);let F=aa[L];if(!F)return new Error(`Cipher (${L}) not supported for encrypted OpenSSH private key`);let k=Buffer.from(C.slice(b+1),"hex");if(k.length!==F.ivLen)return new Error("Malformed encrypted OpenSSH private key");if(!e)return new Error("Encrypted OpenSSH private key detected, but no passphrase given");let K=dr(k,0,8),ee=Ai("md5").update(e).update(K).digest();for(;ee.length<F.keyLen;)ee=_i(ee,Ai("md5").update(ee).update(e).update(K).digest());ee.length>F.keyLen&&(ee=dr(ee,0,F.keyLen));try{let O=ca(L,ee,k);O.setAutoPadding(!1),s=_i(O.update(s),O.final()),o=!0}catch(O){return O}}}}let a,c,f,l,u,h,g="Malformed OpenSSH private key";switch(o&&(g+=". Bad passphrase?"),r[1]){case"RSA":a="ssh-rsa",c=gn("RSA PRIVATE",s);try{h=new Re.Reader(s),h.readSequence(),h.readInt();let y=h.readString(Re.Integer,!0);if(y===null)return new Error(g);let _=h.readString(Re.Integer,!0);if(_===null)return new Error(g);f=yi(y,_),l=bi(y,_)}catch{return new Error(g)}u="sha1";break;case"DSA":a="ssh-dss",c=gn("DSA PRIVATE",s);try{h=new Re.Reader(s),h.readSequence(),h.readInt();let y=h.readString(Re.Integer,!0);if(y===null)return new Error(g);let _=h.readString(Re.Integer,!0);if(_===null)return new Error(g);let b=h.readString(Re.Integer,!0);if(b===null)return new Error(g);let C=h.readString(Re.Integer,!0);if(C===null)return new Error(g);f=xi(y,_,b,C),l=Si(y,_,b,C)}catch{return new Error(g)}u="sha1";break;case"EC":{let y,_,b;try{h=new Re.Reader(s),h.readSequence(),h.readInt(),_=h.readString(Re.OctetString,!0),h.readByte();let L=h.readLength();if(L!==null){if(h._offset=L,b=h.readOID(),b===null)return new Error(g);switch(b){case"1.2.840.10045.3.1.7":y="prime256v1",a="ecdsa-sha2-nistp256",u="sha256";break;case"1.3.132.0.34":y="secp384r1",a="ecdsa-sha2-nistp384",u="sha384";break;case"1.3.132.0.35":y="secp521r1",a="ecdsa-sha2-nistp521",u="sha512";break;default:return new Error(`Unsupported private key EC OID: ${b}`)}}else return new Error(g)}catch{return new Error(g)}c=gn("EC PRIVATE",s);let C=$g(y,_);f=ua(b,C),l=da(b,C);break}}return new Ss(a,"",c,f,l,u,o)}}function ws(n,t,e,r,s,i,o){this.type=n,this.comment=t,this[pn]=e,this[In]=r,this[Gn]=s,this[Un]=i,this[Or]=o}ws.prototype=wi;{let n=Buffer.alloc(0),t=Buffer.from([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),e=Buffer.from([0,0,0,0]),r=Buffer.from([0,0,0,1]),s=/^PuTTY-User-Key-File-2: (ssh-(?:rsa|dss))\r?\nEncryption: (aes256-cbc|none)\r?\nComment: ([^\r\n]*)\r?\nPublic-Lines: \d+\r?\n([\s\S]+?)\r?\nPrivate-Lines: \d+\r?\n([\s\S]+?)\r?\nPrivate-MAC: ([^\r\n]+)/;ws.parse=(i,o)=>{let a=s.exec(i);if(a===null)return null;let c=a[2],f=c!=="none";if(f&&!o)return new Error("Encrypted PPK private key detected, but no passphrase given");let l=Buffer.from(a[5],"base64");if(f){let I=Ei[c],U=_i(Ai("sha1").update(e).update(o).digest(),Ai("sha1").update(r).update(o).digest());U.length>I.keyLen&&(U=dr(U,0,I.keyLen));try{let R=ca(I.sslName,U,t);R.setAutoPadding(!1),l=_i(R.update(l),R.final())}catch(R){return R}}let u=a[1],h=a[3],g=Buffer.from(a[4],"base64"),y=a[6],_=u.length,b=c.length,C=Buffer.byteLength(h),L=g.length,F=l.length,k=Buffer.allocUnsafe(4+_+4+b+4+C+4+L+4+F),K=0;if(Ot(k,_,K),k.utf8Write(u,K+=4,_),Ot(k,b,K+=_),k.utf8Write(c,K+=4,b),Ot(k,C,K+=b),k.utf8Write(h,K+=4,C),Ot(k,L,K+=C),k.set(g,K+=4),Ot(k,F,K+=L),k.set(l,K+4),o||(o=n),Bg("sha1",Ai("sha1").update("putty-private-key-file-mac-key").update(o).digest()).update(k).digest("hex")!==y)return f?new Error("PPK private key integrity check failed -- bad passphrase?"):new Error("PPK private key integrity check failed");let O,x,w;switch(g._pos=0,la(g,1),u){case"ssh-rsa":{let I=ve(g,g._pos);if(I===void 0)return new Error("Malformed PPK public key");let U=ve(g,g._pos);if(U===void 0)return new Error("Malformed PPK public key");let R=ve(l,0);if(R===void 0)return new Error("Malformed PPK private key");let re=ve(l,l._pos);if(re===void 0)return new Error("Malformed PPK private key");let G=ve(l,l._pos);if(G===void 0)return new Error("Malformed PPK private key");let Y=ve(l,l._pos);if(Y===void 0)return new Error("Malformed PPK private key");O=yi(U,I),x=bi(U,I),w=Lu(U,I,R,Y,re,G);break}case"ssh-dss":{let I=ve(g,g._pos);if(I===void 0)return new Error("Malformed PPK public key");let U=ve(g,g._pos);if(U===void 0)return new Error("Malformed PPK public key");let R=ve(g,g._pos);if(R===void 0)return new Error("Malformed PPK public key");let re=ve(g,g._pos);if(re===void 0)return new Error("Malformed PPK public key");let G=ve(l,0);if(G===void 0)return new Error("Malformed PPK private key");O=xi(I,U,R,re),x=Si(I,U,R,re),w=Uu(I,U,R,re,G);break}}return new ws(u,h,w,O,x,"sha1",f)}}function Cs(n,t,e,r,s){this.type=n,this.comment=t,this[pn]=null,this[In]=e,this[Gn]=r,this[Un]=s,this[Or]=!1}Cs.prototype=wi;{let n;fa?n=/^(((?:ssh-(?:rsa|dss|ed25519))|ecdsa-sha2-nistp(?:256|384|521))(?:-cert-v0[01]@openssh.com)?) ([A-Z0-9a-z/+=]+)(?:$|\s+([\S].*)?)$/:n=/^(((?:ssh-(?:rsa|dss))|ecdsa-sha2-nistp(?:256|384|521))(?:-cert-v0[01]@openssh.com)?) ([A-Z0-9a-z/+=]+)(?:$|\s+([\S].*)?)$/,Cs.parse=t=>{let e=n.exec(t);if(e===null)return null;let r=e[1],s=e[2],i=Buffer.from(e[3],"base64"),o=e[4]||"",a=ve(i,i._pos,!0);return a===void 0||a.indexOf(s)!==0?new Error("Malformed OpenSSH public key"):ha(i,s,o,r)}}function Is(n,t,e,r,s){this.type=n,this.comment=t,this[pn]=null,this[In]=e,this[Gn]=r,this[Un]=s,this[Or]=!1}Is.prototype=wi;{let n=/^---- BEGIN SSH2 PUBLIC KEY ----(?:\r?\n)((?:.{0,72}\r?\n)+)---- END SSH2 PUBLIC KEY ----$/,t=/^[A-Z0-9a-z/+=\r\n]+$/,e=/^([\x21-\x39\x3B-\x7E]{1,64}): ((?:[^\\]*\\\r?\n)*[^\r\n]+)\r?\n/gm,r=/\\\r?\n/g;Is.parse=s=>{let i=n.exec(s);if(i===null)return null;let o=i[1],a=0,c="";for(;i=e.exec(o);){let g=i[1],y=i[2].replace(r,"");if(y.length>1024)return e.lastIndex=0,new Error("Malformed RFC4716 public key");a=e.lastIndex,g.toLowerCase()==="comment"&&(c=y,c.length>1&&c.charCodeAt(0)===34&&c.charCodeAt(c.length-1)===34&&(c=c.slice(1,-1)))}let f=o.slice(a);if(!t.test(f))return new Error("Malformed RFC4716 public key");f=Buffer.from(f,"base64");let l=ve(f,0,!0);if(l===void 0)return new Error("Malformed RFC4716 public key");let u=null,h=null;switch(l){case"ssh-rsa":{let g=ve(f,f._pos);if(g===void 0)return new Error("Malformed RFC4716 public key");let y=ve(f,f._pos);if(y===void 0)return new Error("Malformed RFC4716 public key");u=yi(y,g),h=bi(y,g);break}case"ssh-dss":{let g=ve(f,f._pos);if(g===void 0)return new Error("Malformed RFC4716 public key");let y=ve(f,f._pos);if(y===void 0)return new Error("Malformed RFC4716 public key");let _=ve(f,f._pos);if(_===void 0)return new Error("Malformed RFC4716 public key");let b=ve(f,f._pos);if(b===void 0)return new Error("Malformed RFC4716 public key");u=xi(g,y,_,b),h=Si(g,y,_,b);break}default:return new Error("Malformed RFC4716 public key")}return new Is(l,c,u,h,"sha1")}}function ha(n,t,e,r){if(!Mu(t))return new Error(`Unsupported OpenSSH public key type: ${t}`);let s,i,o=null,a=null;switch(t){case"ssh-rsa":{let c=ve(n,n._pos||0);if(c===void 0)return new Error("Malformed OpenSSH public key");let f=ve(n,n._pos);if(f===void 0)return new Error("Malformed OpenSSH public key");o=yi(f,c),a=bi(f,c),s="sha1";break}case"ssh-dss":{let c=ve(n,n._pos||0);if(c===void 0)return new Error("Malformed OpenSSH public key");let f=ve(n,n._pos);if(f===void 0)return new Error("Malformed OpenSSH public key");let l=ve(n,n._pos);if(l===void 0)return new Error("Malformed OpenSSH public key");let u=ve(n,n._pos);if(u===void 0)return new Error("Malformed OpenSSH public key");o=xi(c,f,l,u),a=Si(c,f,l,u),s="sha1";break}case"ssh-ed25519":{let c=ve(n,n._pos||0);if(c===void 0||c.length!==32)return new Error("Malformed OpenSSH public key");o=Du(c),a=Ou(c),s=null;break}case"ecdsa-sha2-nistp256":s="sha256",i="1.2.840.10045.3.1.7";case"ecdsa-sha2-nistp384":s===void 0&&(s="sha384",i="1.3.132.0.34");case"ecdsa-sha2-nistp521":{if(s===void 0&&(s="sha512",i="1.3.132.0.35"),!la(n,1))return new Error("Malformed OpenSSH public key");let c=ve(n,n._pos||0);if(c===void 0)return new Error("Malformed OpenSSH public key");o=ua(i,c),a=da(i,c);break}default:return new Error(`Unsupported OpenSSH public key type: ${t}`)}return new Cs(r,e,o,a,s)}function Mu(n){switch(n){case"ssh-rsa":case"ssh-dss":case"ecdsa-sha2-nistp256":case"ecdsa-sha2-nistp384":case"ecdsa-sha2-nistp521":return!0;case"ssh-ed25519":if(fa)return!0;default:return!1}}function $u(n){return n?typeof n[Or]=="boolean":!1}function Fu(n,t){if($u(n))return n;let e;if(Buffer.isBuffer(n))e=n,n=n.utf8Slice(0,n.length).trim();else if(typeof n=="string")n=n.trim();else return new Error("Key data must be a Buffer or string");if(t!=null){if(typeof t=="string")t=Buffer.from(t);else if(!Buffer.isBuffer(t))return new Error("Passphrase must be a string or Buffer when supplied")}let r;if((r=xs.parse(n,t))!==null||(r=Ss.parse(n,t))!==null||(r=ws.parse(n,t))!==null||(r=Cs.parse(n))!==null||(r=Is.parse(n))!==null)return r;if(e){bs.init(e,0);let s=bs.readString(!0);s!==void 0&&(n=bs.readRaw(),n!==void 0&&(r=ha(n,s,"",s),r instanceof Error&&(r=null))),bs.clear()}return r||new Error("Unsupported key format")}Hu.exports={isParsedKey:$u,isSupportedKeyType:Mu,parseDERKey:(n,t)=>ha(n,t,"",t),parseKey:Fu}});var _a=at((Qx,Xu)=>{"use strict";var{Socket:Ku}=require("net"),{Duplex:Vu}=require("stream"),{resolve:Fg}=require("path"),{readFile:Qu}=require("fs"),{execFile:Hg,spawn:Qg}=require("child_process"),{isParsedKey:Wu,parseKey:Ii}=Yn(),{makeBufferParser:Wg,readUInt32BE:Ea,writeUInt32BE:Jt,writeUInt32LE:qu}=hn();function Ci(n){let t=!1;return(...e)=>{t||(t=!0,n(...e))}}function qg(n,t){let e=Buffer.allocUnsafe(n.length+t.length);return n.copy(e,0),t.copy(e,n.length),e}function ga(){}var Kg=Buffer.alloc(0),yt=Wg(),vi=class{getIdentities(t){t(new Error("Missing getIdentities() implementation"))}sign(t,e,r,s){typeof r=="function"&&(s=r),s(new Error("Missing sign() implementation"))}},$r=class extends vi{constructor(t){super(),this.socketPath=t}getStream(t){t=Ci(t);let e=new Ku;e.on("connect",()=>{t(null,e)}),e.on("close",r).on("end",r).on("error",r),e.connect(this.socketPath);function r(){try{e.destroy()}catch{}t(new Error("Failed to connect to agent"))}}getIdentities(t){t=Ci(t),this.getStream((e,r)=>{function s(o){if(r)try{r.destroy()}catch{}o||(o=new Error("Failed to retrieve identities from agent")),t(o)}if(e)return s(e);let i=new ma(!0);i.on("error",s),i.pipe(r).pipe(i),r.on("close",s).on("end",s).on("error",s),i.getIdentities((o,a)=>{if(o)return s(o);try{r.destroy()}catch{}t(null,a)})})}sign(t,e,r,s){typeof r=="function"?(s=r,r=void 0):(typeof r!="object"||r===null)&&(r=void 0),s=Ci(s),this.getStream((i,o)=>{function a(f){if(o)try{o.destroy()}catch{}f||(f=new Error("Failed to sign data with agent")),s(f)}if(i)return a(i);let c=new ma(!0);c.on("error",a),c.pipe(o).pipe(c),o.on("close",a).on("end",a).on("error",a),c.sign(t,e,r,(f,l)=>{if(f)return a(f);try{o.destroy()}catch{}s(null,l)})})}},Gu=(()=>{let o=Fg(__dirname,"..","util/pagent.exe"),a={10:new Error("Invalid pagent.exe arguments"),11:new Error("Pageant is not running"),12:new Error("pagent.exe could not create an mmap"),13:new Error("pagent.exe could not set mode for stdin"),14:new Error("pagent.exe could not set mode for stdout"),15:new Error("pagent.exe did not get expected input payload")};function c(l){l.buffer=null,l.proc&&(l.proc.kill(),l.proc=void 0)}class f extends Vu{constructor(){super(),this.proc=void 0,this.buffer=null}_read(u){}_write(u,h,g){if(this.buffer===null)this.buffer=u;else{let C=Buffer.allocUnsafe(this.buffer.length+u.length);this.buffer.copy(C,0),u.copy(C,this.buffer.length),this.buffer=C}if(this.buffer.length<4)return g();let y=Ea(this.buffer,0);if(this.buffer.length-4<y)return g();if(u=this.buffer.slice(0,4+y),this.buffer.length>4+y)return g(new Error("Unexpected multiple agent requests"));this.buffer=null;let _,b=this.proc=Qg(o,[u.length]);b.stdout.on("data",C=>{this.push(C)}),b.on("error",C=>{_=C,g(_)}),b.on("close",C=>{if(this.proc=void 0,!_){if(_=a[C])return g(_);g()}}),b.stdin.end(u)}_final(u){c(this),u()}_destroy(u,h){c(this),h()}}return class extends $r{getStream(u){u(null,new f)}}})(),Yu=(()=>{let n=/^!<socket >(\d+) s ([A-Z0-9]{8}-[A-Z0-9]{8}-[A-Z0-9]{8}-[A-Z0-9]{8})/;return class extends $r{getStream(e){e=Ci(e);let r=this.socketPath,s=!1;Qu(r,function i(o,a){if(o){if(s)return e(new Error("Invalid cygwin unix socket path"));Hg("cygpath",["-w",r],(ee,O,x)=>{if(ee||O.length===0)return e(new Error("Invalid cygwin unix socket path"));s=!0,r=O.toString().replace(/[\r\n]/g,""),Qu(r,i)});return}let c=n.exec(a.toString("ascii"));if(!c)return e(new Error("Malformed cygwin unix socket file"));let f,l=0,u=!1,h=[],g,y=Buffer.alloc(12),_=parseInt(c[1],10),b=c[2].replace(/-/g,""),C=Buffer.allocUnsafe(16);for(let ee=0,O=0;O<32;++ee,O+=2)C[ee]=parseInt(b.substring(O,O+2),16);for(let ee=0;ee<16;ee+=4)qu(C,Ea(C,ee),ee);K();function L(){l=0,f="secret",g.write(C)}function F(ee){if(l+=ee.length,f==="secret"){l===16&&(l=0,f="creds",g.write(y));return}if(f==="creds"&&(u||h.push(ee),l===12)){if(g.removeListener("connect",L),g.removeListener("data",F),g.removeListener("error",k),g.removeListener("end",k),g.removeListener("close",k),u)return e(null,g);u=!0,y=Buffer.concat(h),qu(y,process.pid,0),g.on("error",()=>{}),g.destroy(),K()}}function k(){e(new Error("Problem negotiating cygwin unix socket security"))}function K(){g=new Ku,g.on("connect",L),g.on("data",F),g.on("error",k),g.on("end",k),g.on("close",k),g.connect(_)}})}}})(),Vg=/^[/\\][/\\]\.[/\\]pipe[/\\].+/;function zu(n){return process.platform==="win32"&&!Vg.test(n)?n==="pageant"?new Gu:new Yu(n):new $r(n)}var ma=(()=>{function f(x){let w;for(;x[L].length;){let I=x[L][0][u];if(I===void 0)break;x[L].shift(),w=x.push(I)}return w}let l=Symbol("Inbound Request Type"),u=Symbol("Inbound Request Response"),h=Symbol("Inbound Request Context");class g{constructor(w,I){this[l]=w,this[u]=void 0,this[h]=I}hasResponded(){return this[u]!==void 0}getType(){return this[l]}getContext(){return this[h]}}function y(x,w,I){return w[u]=I,f(x)}function _(x){if(x[k]=null,x[F]===0){let w=x[L];if(w&&w.length){x[L]=[];for(let I of w)I.cb(new Error("No reply from server"))}}try{x.end()}catch{}setImmediate(()=>{x[O]||x.emit("end"),x[ee]||x.emit("close")})}function b(){this[ee]=!0}function C(){this[O]=!0}let L=Symbol("Requests"),F=Symbol("Agent Protocol Role"),k=Symbol("Agent Protocol Buffer"),K=Symbol("Agent Protocol Current Message Length"),ee=Symbol("Agent Protocol Closed"),O=Symbol("Agent Protocol Ended");return class extends Vu{constructor(w){super({autoDestroy:!0,emitClose:!1}),this[F]=w?0:1,this[L]=[],this[k]=null,this[K]=-1,this.once("end",C),this.once("close",b)}_read(w){}_write(w,I,U){this[k]===null?this[k]=w:this[k]=qg(this[k],w);let R=this[k],re=R.length,G=0;for(;G<re&&!(re<5||(this[K]===-1&&(this[K]=Ea(R,G)),re<4+this[K]));){let Y=R[G+=4];if(++G,this[F]===0){if(this[L].length===0)return U(new Error("Received unexpected message from server"));let te=this[L].shift();switch(Y){case 5:te.cb(new Error("Agent responded with failure"));break;case 12:{if(te.type!==11)return U(new Error("Agent responded with wrong message type"));yt.init(R,G);let ce=yt.readUInt32BE();if(ce===void 0)return yt.clear(),U(new Error("Malformed agent response"));let D=[];for(let v=0;v<ce;++v){let N=yt.readString();if(N===void 0)return yt.clear(),U(new Error("Malformed agent response"));let H=yt.readString(!0);if(H===void 0)return yt.clear(),U(new Error("Malformed agent response"));N=Ii(N),!(N instanceof Error)&&(N.comment=N.comment||H,D.push(N))}G=yt.pos(),yt.clear(),te.cb(null,D);break}case 14:{if(te.type!==13)return U(new Error("Agent responded with wrong message type"));yt.init(R,G);let ce=yt.readString();if(G=yt.pos(),yt.clear(),ce===void 0)return U(new Error("Malformed agent response"));if(yt.init(ce,0),yt.readString(!0),ce=yt.readString(),yt.clear(),ce===void 0)return U(new Error("Malformed OpenSSH signature format"));te.cb(null,ce);break}default:return U(new Error("Agent responded with unsupported message type"))}}else switch(Y){case 11:{let te=new g(Y);this[L].push(te),this.emit("identities",te);break}case 13:{yt.init(R,G);let te=yt.readString(),ce=yt.readString(),D=yt.readUInt32BE();if(G=yt.pos(),yt.clear(),D===void 0){let X=new g(Y);return this[L].push(X),this.failureReply(X)}if(te=Ii(te),te instanceof Error){let X=new g(Y);return this[L].push(X),this.failureReply(X)}let v={hash:void 0},N;te.type==="ssh-rsa"&&(D&2?(N="rsa-sha2-256",v.hash="sha256"):D&4&&(N="rsa-sha2-512",v.hash="sha512")),N===void 0&&(N=te.type);let H=new g(Y,N);this[L].push(H),this.emit("sign",H,te,ce,v);break}default:{let te=new g(Y);this[L].push(te),this.failureReply(te)}}if(this[K]=-1,G===re){this[k]=null;break}else this[k]=R=R.slice(G),re=R.length,G=0}U()}_destroy(w,I){_(this),I()}_final(w){_(this),w()}sign(w,I,U,R){if(this[F]!==0)throw new Error("Client-only method called with server role");typeof U=="function"?(R=U,U=void 0):(typeof U!="object"||U===null)&&(U=void 0);let re=0;if(w=Ii(w),w instanceof Error)throw new Error("Invalid public key argument");if(w.type==="ssh-rsa"&&U)switch(U.hash){case"sha256":re=2;break;case"sha512":re=4;break}w=w.getPublicSSH();let G=13,Y=w.length,te=I.length,ce=0,D=Buffer.allocUnsafe(9+Y+4+te+4);return Jt(D,D.length-4,ce),D[ce+=4]=G,Jt(D,Y,++ce),w.copy(D,ce+=4),Jt(D,te,ce+=Y),I.copy(D,ce+=4),Jt(D,re,ce+=te),typeof R!="function"&&(R=ga),this[L].push({type:G,cb:R}),this.push(D)}getIdentities(w){if(this[F]!==0)throw new Error("Client-only method called with server role");let I=11,U=0,R=Buffer.allocUnsafe(5);return Jt(R,R.length-4,U),R[U+=4]=I,typeof w!="function"&&(w=ga),this[L].push({type:I,cb:w}),this.push(R)}failureReply(w){if(this[F]!==1)throw new Error("Server-only method called with client role");if(!(w instanceof g))throw new Error("Wrong request argument");if(w.hasResponded())return!0;let I=0,U=Buffer.allocUnsafe(5);return Jt(U,U.length-4,I),U[I+=4]=5,y(this,w,U)}getIdentitiesReply(w,I){if(this[F]!==1)throw new Error("Server-only method called with client role");if(!(w instanceof g))throw new Error("Wrong request argument");if(w.hasResponded())return!0;if(w.getType()!==11)throw new Error("Invalid response to request");if(!Array.isArray(I))throw new Error("Keys argument must be an array");let U=4,R=[];for(let Y=0;Y<I.length;++Y){let te=I[Y];if(typeof te!="object"||te===null)throw new Error(`Invalid key entry: ${te}`);let ce,D;if(Wu(te))ce=te;else if(Wu(te.pubKey))ce=te.pubKey;else if(typeof te.pubKey!="object"||te.pubKey===null||({pubKey:ce,comment:D}=te.pubKey,ce=Ii(ce),ce instanceof Error))continue;D=ce.comment||D,ce=ce.getPublicSSH(),U+=4+ce.length,D&&typeof D=="string"?D=Buffer.from(D):Buffer.isBuffer(D)||(D=Kg),U+=4+D.length,R.push({pubKey:ce,comment:D})}let re=0,G=Buffer.allocUnsafe(5+U);Jt(G,G.length-4,re),G[re+=4]=12,Jt(G,R.length,++re),re+=4;for(let Y=0;Y<R.length;++Y){let{pubKey:te,comment:ce}=R[Y];Jt(G,te.length,re),te.copy(G,re+=4),Jt(G,ce.length,re+=te.length),re+=4,ce.length&&(ce.copy(G,re),re+=ce.length)}return y(this,w,G)}signReply(w,I){if(this[F]!==1)throw new Error("Server-only method called with client role");if(!(w instanceof g))throw new Error("Wrong request argument");if(w.hasResponded())return!0;if(w.getType()!==13)throw new Error("Invalid response to request");if(!Buffer.isBuffer(I))throw new Error("Signature argument must be a Buffer");if(I.length===0)throw new Error("Signature argument must be non-empty");let U=0,R=w.getContext(),re=Buffer.byteLength(R),G=Buffer.allocUnsafe(13+re+4+I.length);return Jt(G,G.length-4,U),G[U+=4]=14,Jt(G,4+re+4+I.length,++U),Jt(G,re,U+=4),G.utf8Write(R,U+=4,re),Jt(G,I.length,U+=re),I.copy(G,U+=4),y(this,w,G)}}})(),pa=Symbol("Agent"),mn=Symbol("Agent Keys"),Dn=Symbol("Agent Keys Index"),Mr=Symbol("Agent Init Callbacks"),Aa=class{constructor(t){if(typeof t=="string")t=zu(t);else if(!ju(t))throw new Error("Invalid agent argument");this[pa]=t,this[mn]=null,this[Dn]=-1,this[Mr]=null}init(t){if(typeof t!="function"&&(t=ga),this[mn]===null)if(this[Mr]===null){this[Mr]=[t];let e=(...r)=>{process.nextTick(()=>{let s=this[Mr];this[Mr]=null;for(let i of s)i(...r)})};this[pa].getIdentities(Ci((r,s)=>{if(r)return e(r);if(!Array.isArray(s))return e(new Error("Agent implementation failed to provide keys"));let i=[];for(let o of s)o=Ii(o),!(o instanceof Error)&&i.push(o);this[mn]=i,this[Dn]=-1,e()}))}else this[Mr].push(t);else process.nextTick(t)}nextKey(){return this[mn]===null||++this[Dn]>=this[mn].length?!1:this[mn][this[Dn]]}currentKey(){return this[mn]===null||this[Dn]>=this[mn].length?null:this[mn][this[Dn]]}pos(){return this[mn]===null||this[Dn]>=this[mn].length?-1:this[Dn]}reset(){this[Dn]=-1}sign(...t){this[pa].sign(...t)}};function ju(n){return n instanceof vi}Xu.exports={AgentContext:Aa,AgentProtocol:ma,BaseAgent:vi,createAgent:zu,CygwinAgent:Yu,isAgent:ju,OpenSSHAgent:$r,PageantAgent:Gu}});var Ia=at((Wx,Ju)=>{"use strict";var{kMaxLength:Gg}=require("buffer"),{createInflate:Yg,constants:{DEFLATE:zg,INFLATE:jg,Z_DEFAULT_CHUNK:Xg,Z_DEFAULT_COMPRESSION:Jg,Z_DEFAULT_MEMLEVEL:Zg,Z_DEFAULT_STRATEGY:e0,Z_DEFAULT_WINDOWBITS:t0,Z_PARTIAL_FLUSH:n0}}=require("zlib"),r0=Yg()._handle.constructor;function i0(){throw new Error("Should not get here")}function s0(n,t,e){let r=this._owner,s=new Error(n);s.errno=t,s.code=e,r._err=s}function wa(n){n._handle&&(n._handle.close(),n._handle=null)}var vs=class{constructor(t){let e=t0,r=Jg,s=Zg,i=e0,o=void 0;this._err=void 0,this._writeState=new Uint32Array(2),this._chunkSize=Xg,this._maxOutputLength=Gg,this._outBuffer=Buffer.allocUnsafe(this._chunkSize),this._outOffset=0,this._handle=new r0(t),this._handle._owner=this,this._handle.onerror=s0,this._handle.init(e,r,s,i,this._writeState,i0,o)}writeSync(t,e){let r=this._handle;if(!r)throw new Error("Invalid Zlib instance");let s=t.length,i=this._chunkSize-this._outOffset,o=0,a,c,f,l=0,u=this._writeState,h=this._outBuffer,g=this._outOffset,y=this._chunkSize;for(;;){if(r.writeSync(n0,t,o,s,h,g,i),this._err)throw this._err;a=u[0],c=u[1];let b=s-c,C=i-a;if(C>0){let L=g===0&&C===h.length?h:h.slice(g,g+C);if(g+=C,f?f.push===void 0?f=[f,L]:f.push(L):f=L,l+=L.byteLength,l>this._maxOutputLength)throw wa(this),new Error(`Output length exceeded maximum of ${this._maxOutputLength}`)}else if(C!==0)throw new Error("have should not go down");if((a===0||g>=y)&&(i=y,g=0,h=Buffer.allocUnsafe(y)),a===0)o+=b,s=c;else break}if(this._outBuffer=h,this._outOffset=g,l===0&&(f=Buffer.alloc(0)),e)return f.totalLen=l,f;if(f.push===void 0)return f;let _=Buffer.allocUnsafe(l);for(let b=0,C=0;b<f.length;++b){let L=f[b];_.set(L,C),C+=L.length}return _}},ya=class{constructor(t){this.allocStart=0,this.allocStartKEX=0,this._protocol=t,this._zlib=new vs(zg)}cleanup(){this._zlib&&wa(this._zlib)}alloc(t,e){return Buffer.allocUnsafe(t)}finalize(t,e){if(this._protocol._kexinit===void 0||e){let r=this._zlib.writeSync(t,!0),s=this._protocol._cipher.allocPacket(r.totalLen);if(r.push===void 0)s.set(r,5);else for(let i=0,o=5;i<r.length;++i){let a=r[i];s.set(a,o),o+=a.length}return s}return t}},ba=class{constructor(t){this.allocStart=5,this.allocStartKEX=5,this._protocol=t}cleanup(){}alloc(t,e){return this._protocol._kexinit===void 0||e?this._protocol._cipher.allocPacket(t):Buffer.allocUnsafe(t)}finalize(t,e){return t}},xa=class{constructor(){this._zlib=new vs(jg)}cleanup(){this._zlib&&wa(this._zlib)}read(t){return this._zlib.writeSync(t,!1)}},Sa=class{cleanup(){}read(t){return t}};Ju.exports={PacketReader:Sa,PacketWriter:ba,ZlibPacketReader:xa,ZlibPacketWriter:ya}});var rd=at((qx,nd)=>{"use strict";var{bufferSlice:Ca,bufferParser:T,doFatalError:ht,sigSSHToASN1:Zu,writeUInt32BE:ed}=hn(),{CHANNEL_OPEN_FAILURE:o0,COMPAT:a0,MESSAGE:mt,TERMINAL_MODE:td}=Ln(),{parseKey:c0}=Yn(),f0=Array.from(Object.entries(td)).reduce((n,[t,e])=>({...n,[t]:e}),{});nd.exports={[mt.DISCONNECT]:(n,t)=>{T.init(t,1);let e=T.readUInt32BE(),r=T.readString(!0),s=T.readString();if(T.clear(),s===void 0)return ht(n,"Inbound: Malformed DISCONNECT packet");n._debug&&n._debug(`Inbound: Received DISCONNECT (${e}, "${r}")`);let i=n._handlers.DISCONNECT;i&&i(n,e,r)},[mt.IGNORE]:(n,t)=>{n._debug&&n._debug("Inbound: Received IGNORE")},[mt.UNIMPLEMENTED]:(n,t)=>{T.init(t,1);let e=T.readUInt32BE();if(T.clear(),e===void 0)return ht(n,"Inbound: Malformed UNIMPLEMENTED packet");n._debug&&n._debug(`Inbound: Received UNIMPLEMENTED (seqno ${e})`)},[mt.DEBUG]:(n,t)=>{T.init(t,1);let e=T.readBool(),r=T.readString(!0),s=T.readString();if(T.clear(),s===void 0)return ht(n,"Inbound: Malformed DEBUG packet");n._debug&&n._debug("Inbound: Received DEBUG");let i=n._handlers.DEBUG;i&&i(n,e,r)},[mt.SERVICE_REQUEST]:(n,t)=>{T.init(t,1);let e=T.readString(!0);if(T.clear(),e===void 0)return ht(n,"Inbound: Malformed SERVICE_REQUEST packet");n._debug&&n._debug(`Inbound: Received SERVICE_REQUEST (${e})`);let r=n._handlers.SERVICE_REQUEST;r&&r(n,e)},[mt.SERVICE_ACCEPT]:(n,t)=>{T.init(t,1);let e=T.readString(!0);if(T.clear(),e===void 0)return ht(n,"Inbound: Malformed SERVICE_ACCEPT packet");n._debug&&n._debug(`Inbound: Received SERVICE_ACCEPT (${e})`);let r=n._handlers.SERVICE_ACCEPT;r&&r(n,e)},[mt.EXT_INFO]:(n,t)=>{T.init(t,1);let e=T.readUInt32BE(),r;if(e!==void 0){r=[];for(let i=0;i<e;++i){let o=T.readString(!0),a=T.readString();if(a!==void 0)if(o==="server-sig-algs"){let c=a.latin1Slice(0,a.length).split(",");r.push({name:o,algs:c});continue}else continue;r=void 0;break}}if(T.clear(),r===void 0)return ht(n,"Inbound: Malformed EXT_INFO packet");n._debug&&n._debug("Inbound: Received EXT_INFO");let s=n._handlers.EXT_INFO;s&&s(n,r)},[mt.USERAUTH_REQUEST]:(n,t)=>{T.init(t,1);let e=T.readString(!0),r=T.readString(!0),s=T.readString(!0),i,o;switch(s){case"none":i=null;break;case"password":{let c=T.readBool();if(c!==void 0&&(i=T.readString(!0),i!==void 0&&c)){let f=T.readString(!0);f!==void 0?i={oldPassword:i,newPassword:f}:i=void 0}break}case"publickey":{let c=T.readBool();if(c!==void 0){let f=T.readString(!0),l=f,u=T.readString(),h;switch(f){case"rsa-sha2-256":l="ssh-rsa",h="sha256";break;case"rsa-sha2-512":l="ssh-rsa",h="sha512";break}if(c){let g=T.pos(),y=T.readString();if(y!==void 0&&(y.length>4+f.length+4&&y.utf8Slice(4,4+f.length)===f&&(y=Ca(y,4+f.length+4)),y=Zu(y,l),y)){let _=n._kex.sessionID,b=Buffer.allocUnsafe(4+_.length+g);ed(b,_.length,0),b.set(_,4),b.set(new Uint8Array(t.buffer,t.byteOffset,g),4+_.length),i={keyAlgo:l,key:u,signature:y,blob:b,hashAlgo:h}}}else i={keyAlgo:l,key:u,hashAlgo:h},o="publickey -- check"}break}case"hostbased":{let c=T.readString(!0),f=c,l=T.readString(),u=T.readString(!0),h=T.readString(!0),g;switch(c){case"rsa-sha2-256":f="ssh-rsa",g="sha256";break;case"rsa-sha2-512":f="ssh-rsa",g="sha512";break}let y=T.pos(),_=T.readString();if(_!==void 0&&(_.length>4+c.length+4&&_.utf8Slice(4,4+c.length)===c&&(_=Ca(_,4+c.length+4)),_=Zu(_,f),_!==void 0)){let b=n._kex.sessionID,C=Buffer.allocUnsafe(4+b.length+y);ed(C,b.length,0),C.set(b,4),C.set(new Uint8Array(t.buffer,t.byteOffset,y),4+b.length),i={keyAlgo:f,key:l,signature:_,blob:C,localHostname:u,localUsername:h,hashAlgo:g}}break}case"keyboard-interactive":T.skipString(),i=T.readList();break;default:s!==void 0&&(i=T.readRaw())}if(T.clear(),i===void 0)return ht(n,"Inbound: Malformed USERAUTH_REQUEST packet");o===void 0&&(o=s),n._authsQueue.push(s),n._debug&&n._debug(`Inbound: Received USERAUTH_REQUEST (${o})`);let a=n._handlers.USERAUTH_REQUEST;a&&a(n,e,r,s,i)},[mt.USERAUTH_FAILURE]:(n,t)=>{T.init(t,1);let e=T.readList(),r=T.readBool();if(T.clear(),r===void 0)return ht(n,"Inbound: Malformed USERAUTH_FAILURE packet");n._debug&&n._debug(`Inbound: Received USERAUTH_FAILURE (${e})`),n._authsQueue.shift();let s=n._handlers.USERAUTH_FAILURE;s&&s(n,e,r)},[mt.USERAUTH_SUCCESS]:(n,t)=>{n._debug&&n._debug("Inbound: Received USERAUTH_SUCCESS"),n._authsQueue.shift();let e=n._handlers.USERAUTH_SUCCESS;e&&e(n)},[mt.USERAUTH_BANNER]:(n,t)=>{T.init(t,1);let e=T.readString(!0),r=T.readString();if(T.clear(),r===void 0)return ht(n,"Inbound: Malformed USERAUTH_BANNER packet");n._debug&&n._debug("Inbound: Received USERAUTH_BANNER");let s=n._handlers.USERAUTH_BANNER;s&&s(n,e)},60:(n,t)=>{if(!n._authsQueue.length){n._debug&&n._debug("Inbound: Received payload type 60 without auth");return}switch(n._authsQueue[0]){case"password":{T.init(t,1);let e=T.readString(!0),r=T.readString();if(T.clear(),r===void 0)return ht(n,"Inbound: Malformed USERAUTH_PASSWD_CHANGEREQ packet");n._debug&&n._debug("Inbound: Received USERAUTH_PASSWD_CHANGEREQ");let s=n._handlers.USERAUTH_PASSWD_CHANGEREQ;s&&s(n,e);break}case"publickey":{T.init(t,1);let e=T.readString(!0),r=T.readString();if(T.clear(),r===void 0)return ht(n,"Inbound: Malformed USERAUTH_PK_OK packet");n._debug&&n._debug("Inbound: Received USERAUTH_PK_OK"),n._authsQueue.shift();let s=n._handlers.USERAUTH_PK_OK;s&&s(n,e,r);break}case"keyboard-interactive":{T.init(t,1);let e=T.readString(!0),r=T.readString(!0);T.readString();let s=T.readUInt32BE(),i;if(s!==void 0){i=new Array(s);let a;for(a=0;a<s;++a){let c=T.readString(!0),f=T.readBool();if(f===void 0)break;i[a]={prompt:c,echo:f}}a!==s&&(i=void 0)}if(T.clear(),i===void 0)return ht(n,"Inbound: Malformed USERAUTH_INFO_REQUEST packet");n._debug&&n._debug("Inbound: Received USERAUTH_INFO_REQUEST");let o=n._handlers.USERAUTH_INFO_REQUEST;o&&o(n,e,r,i);break}default:n._debug&&n._debug("Inbound: Received unexpected payload type 60")}},61:(n,t)=>{if(!n._authsQueue.length){n._debug&&n._debug("Inbound: Received payload type 61 without auth");return}if(n._authsQueue[0]!=="keyboard-interactive")return ht(n,"Inbound: Received unexpected payload type 61");T.init(t,1);let e=T.readUInt32BE(),r;if(e!==void 0){r=new Array(e);let i;for(i=0;i<e;++i){let o=T.readString(!0);if(o===void 0)break;r[i]=o}i!==e&&(r=void 0)}if(T.clear(),r===void 0)return ht(n,"Inbound: Malformed USERAUTH_INFO_RESPONSE packet");n._debug&&n._debug("Inbound: Received USERAUTH_INFO_RESPONSE");let s=n._handlers.USERAUTH_INFO_RESPONSE;s&&s(n,r)},[mt.GLOBAL_REQUEST]:(n,t)=>{T.init(t,1);let e=T.readString(!0),r=T.readBool(),s;if(r!==void 0)switch(e){case"tcpip-forward":case"cancel-tcpip-forward":{let o=T.readString(!0),a=T.readUInt32BE();a!==void 0&&(s={bindAddr:o,bindPort:a});break}case"streamlocal-forward@openssh.com":case"cancel-streamlocal-forward@openssh.com":{let o=T.readString(!0);o!==void 0&&(s={socketPath:o});break}case"no-more-sessions@openssh.com":s=null;break;case"hostkeys-00@openssh.com":{for(s=[];T.avail()>0;){let o=T.readString();if(o===void 0){s=void 0;break}let a=c0(o);a instanceof Error||s.push(a)}break}default:s=T.readRaw()}if(T.clear(),s===void 0)return ht(n,"Inbound: Malformed GLOBAL_REQUEST packet");n._debug&&n._debug(`Inbound: GLOBAL_REQUEST (${e})`);let i=n._handlers.GLOBAL_REQUEST;i?i(n,e,r,s):n.requestFailure()},[mt.REQUEST_SUCCESS]:(n,t)=>{let e=t.length>1?Ca(t,1):null;n._debug&&n._debug("Inbound: REQUEST_SUCCESS");let r=n._handlers.REQUEST_SUCCESS;r&&r(n,e)},[mt.REQUEST_FAILURE]:(n,t)=>{n._debug&&n._debug("Inbound: Received REQUEST_FAILURE");let e=n._handlers.REQUEST_FAILURE;e&&e(n)},[mt.CHANNEL_OPEN]:(n,t)=>{T.init(t,1);let e=T.readString(!0),r=T.readUInt32BE(),s=T.readUInt32BE(),i=T.readUInt32BE(),o;switch(e){case"forwarded-tcpip":case"direct-tcpip":{let c=T.readString(!0),f=T.readUInt32BE(),l=T.readString(!0),u=T.readUInt32BE();u!==void 0&&(o={type:e,sender:r,window:s,packetSize:i,data:{destIP:c,destPort:f,srcIP:l,srcPort:u}});break}case"forwarded-streamlocal@openssh.com":case"direct-streamlocal@openssh.com":{let c=T.readString(!0);c!==void 0&&(o={type:e,sender:r,window:s,packetSize:i,data:{socketPath:c}});break}case"x11":{let c=T.readString(!0),f=T.readUInt32BE();f!==void 0&&(o={type:e,sender:r,window:s,packetSize:i,data:{srcIP:c,srcPort:f}});break}default:o={type:e,sender:r,window:s,packetSize:i,data:{}}}if(T.clear(),o===void 0)return ht(n,"Inbound: Malformed CHANNEL_OPEN packet");n._debug&&n._debug(`Inbound: CHANNEL_OPEN (s:${r}, ${e})`);let a=n._handlers.CHANNEL_OPEN;a?a(n,o):n.channelOpenFail(o.sender,o0.ADMINISTRATIVELY_PROHIBITED,"","")},[mt.CHANNEL_OPEN_CONFIRMATION]:(n,t)=>{T.init(t,1);let e=T.readUInt32BE(),r=T.readUInt32BE(),s=T.readUInt32BE(),i=T.readUInt32BE(),o=T.avail()?T.readRaw():void 0;if(T.clear(),i===void 0)return ht(n,"Inbound: Malformed CHANNEL_OPEN_CONFIRMATION packet");n._debug&&n._debug(`Inbound: CHANNEL_OPEN_CONFIRMATION (r:${e}, s:${r})`);let a=n._handlers.CHANNEL_OPEN_CONFIRMATION;a&&a(n,{recipient:e,sender:r,window:s,packetSize:i,data:o})},[mt.CHANNEL_OPEN_FAILURE]:(n,t)=>{T.init(t,1);let e=T.readUInt32BE(),r=T.readUInt32BE(),s=T.readString(!0),i=T.readString();if(T.clear(),i===void 0)return ht(n,"Inbound: Malformed CHANNEL_OPEN_FAILURE packet");n._debug&&n._debug(`Inbound: CHANNEL_OPEN_FAILURE (r:${e})`);let o=n._handlers.CHANNEL_OPEN_FAILURE;o&&o(n,e,r,s)},[mt.CHANNEL_WINDOW_ADJUST]:(n,t)=>{T.init(t,1);let e=T.readUInt32BE(),r=T.readUInt32BE();if(T.clear(),r===void 0)return ht(n,"Inbound: Malformed CHANNEL_WINDOW_ADJUST packet");n._debug&&n._debug(`Inbound: CHANNEL_WINDOW_ADJUST (r:${e}, ${r})`);let s=n._handlers.CHANNEL_WINDOW_ADJUST;s&&s(n,e,r)},[mt.CHANNEL_DATA]:(n,t)=>{T.init(t,1);let e=T.readUInt32BE(),r=T.readString();if(T.clear(),r===void 0)return ht(n,"Inbound: Malformed CHANNEL_DATA packet");n._debug&&n._debug(`Inbound: CHANNEL_DATA (r:${e}, ${r.length})`);let s=n._handlers.CHANNEL_DATA;s&&s(n,e,r)},[mt.CHANNEL_EXTENDED_DATA]:(n,t)=>{T.init(t,1);let e=T.readUInt32BE(),r=T.readUInt32BE(),s=T.readString();if(T.clear(),s===void 0)return ht(n,"Inbound: Malformed CHANNEL_EXTENDED_DATA packet");n._debug&&n._debug(`Inbound: CHANNEL_EXTENDED_DATA (r:${e}, ${s.length})`);let i=n._handlers.CHANNEL_EXTENDED_DATA;i&&i(n,e,s,r)},[mt.CHANNEL_EOF]:(n,t)=>{T.init(t,1);let e=T.readUInt32BE();if(T.clear(),e===void 0)return ht(n,"Inbound: Malformed CHANNEL_EOF packet");n._debug&&n._debug(`Inbound: CHANNEL_EOF (r:${e})`);let r=n._handlers.CHANNEL_EOF;r&&r(n,e)},[mt.CHANNEL_CLOSE]:(n,t)=>{T.init(t,1);let e=T.readUInt32BE();if(T.clear(),e===void 0)return ht(n,"Inbound: Malformed CHANNEL_CLOSE packet");n._debug&&n._debug(`Inbound: CHANNEL_CLOSE (r:${e})`);let r=n._handlers.CHANNEL_CLOSE;r&&r(n,e)},[mt.CHANNEL_REQUEST]:(n,t)=>{T.init(t,1);let e=T.readUInt32BE(),r=T.readString(!0),s=T.readBool(),i;if(s!==void 0)switch(r){case"exit-status":i=T.readUInt32BE(),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${i})`);break;case"exit-signal":{let a,c;if(n._compatFlags&a0.OLD_EXIT){let l=T.readUInt32BE();switch(l){case 1:a="HUP";break;case 2:a="INT";break;case 3:a="QUIT";break;case 6:a="ABRT";break;case 9:a="KILL";break;case 14:a="ALRM";break;case 15:a="TERM";break;default:l!==void 0&&(a=`UNKNOWN (${l})`)}c=!1}else a=T.readString(!0),c=T.readBool(),c===void 0&&(a=void 0);let f=T.readString(!0);T.skipString()!==void 0&&(i={signal:a,coreDumped:c,errorMessage:f}),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${a})`);break}case"pty-req":{let a=T.readString(!0),c=T.readUInt32BE(),f=T.readUInt32BE(),l=T.readUInt32BE(),u=T.readUInt32BE(),h=T.readString();if(h!==void 0){T.init(h,1);let g={};for(;T.avail();){let y=T.readByte();if(y===td.TTY_OP_END)break;let _=f0[y],b=T.readUInt32BE();if(y===void 0||_===void 0||b===void 0){g=void 0;break}g[_]=b}g!==void 0&&(i={term:a,cols:c,rows:f,width:l,height:u,modes:g})}n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break}case"window-change":{let a=T.readUInt32BE(),c=T.readUInt32BE(),f=T.readUInt32BE(),l=T.readUInt32BE();l!==void 0&&(i={cols:a,rows:c,width:f,height:l}),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break}case"x11-req":{let a=T.readBool(),c=T.readString(!0),f=T.readString(),l=T.readUInt32BE();l!==void 0&&(i={single:a,protocol:c,cookie:f,screen:l}),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break}case"env":{let a=T.readString(!0),c=T.readString(!0);c!==void 0&&(i={name:a,value:c}),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${a}=${c})`);break}case"shell":i=null,n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break;case"exec":i=T.readString(!0),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${i})`);break;case"subsystem":i=T.readString(!0),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${i})`);break;case"signal":i=T.readString(!0),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${i})`);break;case"xon-xoff":i=T.readBool(),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${i})`);break;case"auth-agent-req@openssh.com":i=null,n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break;default:i=T.avail()?T.readRaw():null,n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`)}if(T.clear(),i===void 0)return ht(n,"Inbound: Malformed CHANNEL_REQUEST packet");let o=n._handlers.CHANNEL_REQUEST;o&&o(n,e,r,s,i)},[mt.CHANNEL_SUCCESS]:(n,t)=>{T.init(t,1);let e=T.readUInt32BE();if(T.clear(),e===void 0)return ht(n,"Inbound: Malformed CHANNEL_SUCCESS packet");n._debug&&n._debug(`Inbound: CHANNEL_SUCCESS (r:${e})`);let r=n._handlers.CHANNEL_SUCCESS;r&&r(n,e)},[mt.CHANNEL_FAILURE]:(n,t)=>{T.init(t,1);let e=T.readUInt32BE();if(T.clear(),e===void 0)return ht(n,"Inbound: Malformed CHANNEL_FAILURE packet");n._debug&&n._debug(`Inbound: CHANNEL_FAILURE (r:${e})`);let r=n._handlers.CHANNEL_FAILURE;r&&r(n,e)}}});var ks=at((Kx,id)=>{"use strict";var va=new Array(256);[Bs().HANDLERS,rd()].forEach(n=>{for(let[t,e]of Object.entries(n))t=+t,isFinite(t)&&t>=0&&t<va.length&&(va[t]=e)});id.exports=va});var Bs=at((Gx,pd)=>{"use strict";var{createDiffieHellman:l0,createDiffieHellmanGroup:u0,createECDH:d0,createHash:Ba,createPublicKey:h0,diffieHellman:p0,generateKeyPairSync:g0,randomFillSync:m0}=require("crypto"),{Ber:sd}=li(),{COMPAT:Ra,curve25519Supported:A0,DEFAULT_KEX:od,DEFAULT_SERVER_HOST_KEY:ad,DEFAULT_CIPHER:Rs,DEFAULT_MAC:Ns,DEFAULT_COMPRESSION:Ps,DISCONNECT_REASON:Ge,MESSAGE:lt}=Ln(),{CIPHER_INFO:Qr,createCipher:E0,createDecipher:_0,MAC_INFO:cd}=Kn(),{parseDERKey:y0}=Yn(),{bufferFill:b0,bufferParser:Ve,convertSignature:x0,doFatalError:Ye,FastBuffer:S0,sigSSHToASN1:w0,writeUInt32BE:Mt}=hn(),{PacketReader:fd,PacketWriter:ld,ZlibPacketReader:Ts,ZlibPacketWriter:Ls}=Ia(),Fr,I0=2048,C0=8192,v0=Buffer.alloc(0);function ud(n){let t;if(n._compatFlags&Ra.BAD_DHGEX){let e=n._offer.lists.kex,r=e.array,s=!1;for(let i=0;i<r.length;++i)r[i].includes("group-exchange")&&(s||(s=!0,r=r.slice()),r.splice(i--,1));if(s){let i=17+n._offer.totalSize+1+4,o=Buffer.from(r.join(","));i-=e.buffer.length-o.length;let a=n._offer.lists.all,c=new Uint8Array(a.buffer,a.byteOffset+4+e.buffer.length,a.length-(4+e.buffer.length));t=Buffer.allocUnsafe(i),Mt(t,o.length,17),t.set(o,21),t.set(c,21+o.length)}}t===void 0&&(t=Buffer.allocUnsafe(17+n._offer.totalSize+1+4),n._offer.copyAllTo(t,17)),n._debug&&n._debug("Outbound: Sending KEXINIT"),t[0]=lt.KEXINIT,m0(t,1,16),b0(t,0,t.length-5),n._kexinit=t,n._packetRW.write.allocStart=0;{let e=n._packetRW.write.allocStartKEX,r=n._packetRW.write.alloc(t.length,!0);r.set(t,e),n._cipher.encrypt(n._packetRW.write.finalize(r,!0))}}function dd(n,t){let e={kex:void 0,serverHostKey:void 0,cs:{cipher:void 0,mac:void 0,compress:void 0,lang:void 0},sc:{cipher:void 0,mac:void 0,compress:void 0,lang:void 0}};if(Ve.init(t,17),(e.kex=Ve.readList())===void 0||(e.serverHostKey=Ve.readList())===void 0||(e.cs.cipher=Ve.readList())===void 0||(e.sc.cipher=Ve.readList())===void 0||(e.cs.mac=Ve.readList())===void 0||(e.sc.mac=Ve.readList())===void 0||(e.cs.compress=Ve.readList())===void 0||(e.sc.compress=Ve.readList())===void 0||(e.cs.lang=Ve.readList())===void 0||(e.sc.lang=Ve.readList())===void 0)return Ve.clear(),Ye(n,"Received malformed KEXINIT","handshake",Ge.KEY_EXCHANGE_FAILED);let r=Ve.pos(),s=r<t.length&&t[r]===1;Ve.clear();let i=n._offer,o=e,a=i.lists.kex.array;if(n._compatFlags&Ra.BAD_DHGEX){let k=!1;for(let K=0;K<a.length;++K)a[K].indexOf("group-exchange")!==-1&&(k||(k=!0,a=a.slice()),a.splice(K--,1))}let c,f,l,u=n._debug;u&&u("Inbound: Handshake in progress"),u&&u(`Handshake: (local) KEX method: ${a}`),u&&u(`Handshake: (remote) KEX method: ${o.kex}`);let h;if(n._server?(f=a,c=o.kex,h=c.indexOf("ext-info-c")!==-1):(f=o.kex,c=a,h=f.indexOf("ext-info-s")!==-1),n._strictMode===void 0&&(n._server?n._strictMode=c.indexOf("kex-strict-c-v00@openssh.com")!==-1:n._strictMode=f.indexOf("kex-strict-s-v00@openssh.com")!==-1,n._strictMode&&(u&&u("Handshake: strict KEX mode enabled"),n._decipher.inSeqno!==1)))return u&&u("Handshake: KEXINIT not first packet in strict KEX mode"),Ye(n,"Handshake failed: KEXINIT not first packet in strict KEX mode","handshake",Ge.KEY_EXCHANGE_FAILED);for(l=0;l<c.length&&f.indexOf(c[l])===-1;++l);if(l===c.length)return u&&u("Handshake: no matching key exchange algorithm"),Ye(n,"Handshake failed: no matching key exchange algorithm","handshake",Ge.KEY_EXCHANGE_FAILED);e.kex=c[l],u&&u(`Handshake: KEX algorithm: ${c[l]}`),s&&(!o.kex.length||c[l]!==o.kex[0])&&(n._skipNextInboundPacket=!0);let g=i.lists.serverHostKey.array;for(u&&u(`Handshake: (local) Host key format: ${g}`),u&&u(`Handshake: (remote) Host key format: ${o.serverHostKey}`),n._server?(f=g,c=o.serverHostKey):(f=o.serverHostKey,c=g),l=0;l<c.length&&f.indexOf(c[l])===-1;++l);if(l===c.length)return u&&u("Handshake: No matching host key format"),Ye(n,"Handshake failed: no matching host key format","handshake",Ge.KEY_EXCHANGE_FAILED);e.serverHostKey=c[l],u&&u(`Handshake: Host key format: ${c[l]}`);let y=i.lists.cs.cipher.array;for(u&&u(`Handshake: (local) C->S cipher: ${y}`),u&&u(`Handshake: (remote) C->S cipher: ${o.cs.cipher}`),n._server?(f=y,c=o.cs.cipher):(f=o.cs.cipher,c=y),l=0;l<c.length&&f.indexOf(c[l])===-1;++l);if(l===c.length)return u&&u("Handshake: No matching C->S cipher"),Ye(n,"Handshake failed: no matching C->S cipher","handshake",Ge.KEY_EXCHANGE_FAILED);e.cs.cipher=c[l],u&&u(`Handshake: C->S Cipher: ${c[l]}`);let _=i.lists.sc.cipher.array;for(u&&u(`Handshake: (local) S->C cipher: ${_}`),u&&u(`Handshake: (remote) S->C cipher: ${o.sc.cipher}`),n._server?(f=_,c=o.sc.cipher):(f=o.sc.cipher,c=_),l=0;l<c.length&&f.indexOf(c[l])===-1;++l);if(l===c.length)return u&&u("Handshake: No matching S->C cipher"),Ye(n,"Handshake failed: no matching S->C cipher","handshake",Ge.KEY_EXCHANGE_FAILED);e.sc.cipher=c[l],u&&u(`Handshake: S->C cipher: ${c[l]}`);let b=i.lists.cs.mac.array;if(u&&u(`Handshake: (local) C->S MAC: ${b}`),u&&u(`Handshake: (remote) C->S MAC: ${o.cs.mac}`),Qr[e.cs.cipher].authLen>0)e.cs.mac="",u&&u("Handshake: C->S MAC: <implicit>");else{for(n._server?(f=b,c=o.cs.mac):(f=o.cs.mac,c=b),l=0;l<c.length&&f.indexOf(c[l])===-1;++l);if(l===c.length)return u&&u("Handshake: No matching C->S MAC"),Ye(n,"Handshake failed: no matching C->S MAC","handshake",Ge.KEY_EXCHANGE_FAILED);e.cs.mac=c[l],u&&u(`Handshake: C->S MAC: ${c[l]}`)}let C=i.lists.sc.mac.array;if(u&&u(`Handshake: (local) S->C MAC: ${C}`),u&&u(`Handshake: (remote) S->C MAC: ${o.sc.mac}`),Qr[e.sc.cipher].authLen>0)e.sc.mac="",u&&u("Handshake: S->C MAC: <implicit>");else{for(n._server?(f=C,c=o.sc.mac):(f=o.sc.mac,c=C),l=0;l<c.length&&f.indexOf(c[l])===-1;++l);if(l===c.length)return u&&u("Handshake: No matching S->C MAC"),Ye(n,"Handshake failed: no matching S->C MAC","handshake",Ge.KEY_EXCHANGE_FAILED);e.sc.mac=c[l],u&&u(`Handshake: S->C MAC: ${c[l]}`)}let L=i.lists.cs.compress.array;for(u&&u(`Handshake: (local) C->S compression: ${L}`),u&&u(`Handshake: (remote) C->S compression: ${o.cs.compress}`),n._server?(f=L,c=o.cs.compress):(f=o.cs.compress,c=L),l=0;l<c.length&&f.indexOf(c[l])===-1;++l);if(l===c.length)return u&&u("Handshake: No matching C->S compression"),Ye(n,"Handshake failed: no matching C->S compression","handshake",Ge.KEY_EXCHANGE_FAILED);e.cs.compress=c[l],u&&u(`Handshake: C->S compression: ${c[l]}`);let F=i.lists.sc.compress.array;for(u&&u(`Handshake: (local) S->C compression: ${F}`),u&&u(`Handshake: (remote) S->C compression: ${o.sc.compress}`),n._server?(f=F,c=o.sc.compress):(f=o.sc.compress,c=F),l=0;l<c.length&&f.indexOf(c[l])===-1;++l);if(l===c.length)return u&&u("Handshake: No matching S->C compression"),Ye(n,"Handshake failed: no matching S->C compression","handshake",Ge.KEY_EXCHANGE_FAILED);e.sc.compress=c[l],u&&u(`Handshake: S->C compression: ${c[l]}`),e.cs.lang="",e.sc.lang="",n._kex&&(n._kexinit||ud(n),n._decipher._onPayload=hd.bind(n,{firstPacket:!1})),n._kex=k0(e,n,t),n._kex.remoteExtInfoEnabled=h,n._kex.start()}var k0=(()=>{function n(o){let a=0,c=o.length;for(;o[a]===0;)++a,--c;let f;return o[a]&128?(f=Buffer.allocUnsafe(1+c),f[0]=0,o.copy(f,1,a),o=f):c!==o.length&&(f=Buffer.allocUnsafe(c),o.copy(f,0,a),o=f),o}class t{constructor(a,c,f){this._protocol=c,this.sessionID=c._kex?c._kex.sessionID:void 0,this.negotiated=a,this.remoteExtInfoEnabled=!1,this._step=1,this._public=null,this._dh=null,this._sentNEWKEYS=!1,this._receivedNEWKEYS=!1,this._finished=!1,this._hostVerified=!1,this._kexinit=c._kexinit,this._remoteKexinit=f,this._identRaw=c._identRaw,this._remoteIdentRaw=c._remoteIdentRaw,this._hostKey=void 0,this._dhData=void 0,this._sig=void 0}finish(a){if(this._finished)return!1;this._finished=!0;let c=this._protocol._server,f=this.negotiated,l=this.convertPublicKey(this._dhData),u=this.computeSecret(this._dhData);if(u instanceof Error)return u.message=`Error while computing DH secret (${this.type}): ${u.message}`,u.level="handshake",Ye(this._protocol,u,Ge.KEY_EXCHANGE_FAILED);let h=Ba(this.hashName);Cn(h,c?this._remoteIdentRaw:this._identRaw),Cn(h,c?this._identRaw:this._remoteIdentRaw),Cn(h,c?this._remoteKexinit:this._kexinit),Cn(h,c?this._kexinit:this._remoteKexinit);let g=c?this._hostKey.getPublicSSH():this._hostKey;if(Cn(h,g),this.type==="groupex"){let F=this.getDHParams(),k=Buffer.allocUnsafe(4);Mt(k,this._minBits,0),h.update(k),Mt(k,this._prefBits,0),h.update(k),Mt(k,this._maxBits,0),h.update(k),Cn(h,F.prime),Cn(h,F.generator)}Cn(h,c?l:this.getPublicKey());let y=c?this.getPublicKey():l;Cn(h,y),Cn(h,u);let _=h.digest();if(c){let F;switch(this.negotiated.serverHostKey){case"rsa-sha2-256":F="sha256";break;case"rsa-sha2-512":F="sha512";break}this._protocol._debug&&this._protocol._debug("Generating signature ...");let k=this._hostKey.sign(_,F);if(k instanceof Error)return Ye(this._protocol,`Handshake failed: signature generation failed for ${this._hostKey.type} host key: ${k.message}`,"handshake",Ge.KEY_EXCHANGE_FAILED);if(k=x0(k,this._hostKey.type),k===!1)return Ye(this._protocol,`Handshake failed: signature conversion failed for ${this._hostKey.type} host key`,"handshake",Ge.KEY_EXCHANGE_FAILED);let K=this.negotiated.serverHostKey,ee=Buffer.byteLength(K),O=4+ee+4+k.length,x=this._protocol._packetRW.write.allocStartKEX,w=this._protocol._packetRW.write.alloc(5+g.length+4+y.length+4+O,!0);if(w[x]=lt.KEXDH_REPLY,Mt(w,g.length,++x),w.set(g,x+=4),Mt(w,y.length,x+=g.length),w.set(y,x+=4),Mt(w,O,x+=y.length),Mt(w,ee,x+=4),w.utf8Write(K,x+=4,ee),Mt(w,k.length,x+=ee),w.set(k,x+=4),this._protocol._debug){let I;switch(this.type){case"group":I="KEXDH_REPLY";break;case"groupex":I="KEXDH_GEX_REPLY";break;default:I="KEXECDH_REPLY"}this._protocol._debug(`Outbound: Sending ${I}`)}this._protocol._cipher.encrypt(this._protocol._packetRW.write.finalize(w,!0))}else{Ve.init(this._sig,0);let F=Ve.readString(!0);if(!F)return Ye(this._protocol,"Malformed packet while reading signature","handshake",Ge.KEY_EXCHANGE_FAILED);if(F!==f.serverHostKey)return Ye(this._protocol,`Wrong signature type: ${F}, expected: ${f.serverHostKey}`,"handshake",Ge.KEY_EXCHANGE_FAILED);let k=Ve.readString();if(Ve.clear(),k===void 0)return Ye(this._protocol,"Malformed packet while reading signature","handshake",Ge.KEY_EXCHANGE_FAILED);if(!(k=w0(k,F)))return Ye(this._protocol,"Malformed signature","handshake",Ge.KEY_EXCHANGE_FAILED);let K;{Ve.init(this._hostKey,0);let x=Ve.readString(!0),w=this._hostKey.slice(Ve.pos());if(Ve.clear(),K=y0(w,x),K instanceof Error)return K.level="handshake",Ye(this._protocol,K,Ge.KEY_EXCHANGE_FAILED)}let ee;switch(this.negotiated.serverHostKey){case"rsa-sha2-256":ee="sha256";break;case"rsa-sha2-512":ee="sha512";break}this._protocol._debug&&this._protocol._debug("Verifying signature ...");let O=K.verify(_,k,ee);if(O!==!0)return O instanceof Error?this._protocol._debug&&this._protocol._debug(`Signature verification failed: ${O.stack}`):this._protocol._debug&&this._protocol._debug("Signature verification failed"),Ye(this._protocol,"Handshake failed: signature verification failed","handshake",Ge.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Verified signature")}(c||!a)&&Us(this);let b,C,L=F=>{if(b)return Us(this),b.outbound.seqno=this._protocol._cipher.outSeqno,this._protocol._cipher.free(),this._protocol._cipher=E0(b),this._protocol._packetRW.write=C,b=void 0,C=void 0,this._protocol._onHandshakeComplete(f),!1;this.sessionID||(this.sessionID=_);{let te=Buffer.allocUnsafe(4+u.length);Mt(te,u.length,0),te.set(u,4),u=te}let k=Qr[f.cs.cipher],K=Qr[f.sc.cipher],ee=Hr(k.ivLen,this.hashName,u,_,this.sessionID,"A"),O=Hr(K.ivLen,this.hashName,u,_,this.sessionID,"B"),x=Hr(k.keyLen,this.hashName,u,_,this.sessionID,"C"),w=Hr(K.keyLen,this.hashName,u,_,this.sessionID,"D"),I,U;k.authLen||(I=cd[f.cs.mac],U=Hr(I.len,this.hashName,u,_,this.sessionID,"E"));let R,re;K.authLen||(R=cd[f.sc.mac],re=Hr(R.len,this.hashName,u,_,this.sessionID,"F"));let G={inbound:{onPayload:this._protocol._onPayload,seqno:this._protocol._decipher.inSeqno,decipherInfo:c?k:K,decipherIV:c?ee:O,decipherKey:c?x:w,macInfo:c?I:R,macKey:c?U:re},outbound:{onWrite:this._protocol._onWrite,seqno:this._protocol._cipher.outSeqno,cipherInfo:c?K:k,cipherIV:c?O:ee,cipherKey:c?w:x,macInfo:c?R:I,macKey:c?re:U}};this._protocol._decipher.free(),b=G,this._protocol._decipher=_0(G);let Y={read:void 0,write:void 0};switch(f.cs.compress){case"zlib":c?Y.read=new Ts:Y.write=new Ls(this._protocol);break;case"zlib@openssh.com":if(this._protocol._authenticated){c?Y.read=new Ts:Y.write=new Ls(this._protocol);break}default:c?Y.read=new fd:Y.write=new ld(this._protocol)}switch(f.sc.compress){case"zlib":c?Y.write=new Ls(this._protocol):Y.read=new Ts;break;case"zlib@openssh.com":if(this._protocol._authenticated){c?Y.write=new Ls(this._protocol):Y.read=new Ts;break}default:c?Y.write=new ld(this._protocol):Y.read=new fd}return this._protocol._packetRW.read.cleanup(),this._protocol._packetRW.write.cleanup(),this._protocol._packetRW.read=Y.read,C=Y.write,this._public=null,this._dh=null,this._kexinit=this._protocol._kexinit=void 0,this._remoteKexinit=void 0,this._identRaw=void 0,this._remoteIdentRaw=void 0,this._hostKey=void 0,this._dhData=void 0,this._sig=void 0,F?!1:L()};if((c||a)&&(this.finish=L),!c)return L(a)}start(){if(!this._protocol._server){if(this._protocol._debug){let l;this.type==="group"?l="KEXDH_INIT":l="KEXECDH_INIT",this._protocol._debug(`Outbound: Sending ${l}`)}let a=this.getPublicKey(),c=this._protocol._packetRW.write.allocStartKEX,f=this._protocol._packetRW.write.alloc(5+a.length,!0);f[c]=lt.KEXDH_INIT,Mt(f,a.length,++c),f.set(a,c+=4),this._protocol._cipher.encrypt(this._protocol._packetRW.write.finalize(f,!0))}}getPublicKey(){this.generateKeys();let a=this._public;if(a)return this.convertPublicKey(a)}convertPublicKey(a){let c,f=0,l=a.length;for(;a[f]===0;)++f,--l;return a[f]&128?(c=Buffer.allocUnsafe(1+l),c[0]=0,a.copy(c,1,f),c):(l!==a.length&&(c=Buffer.allocUnsafe(l),a.copy(c,0,f),a=c),a)}computeSecret(a){this.generateKeys();try{return n(this._dh.computeSecret(a))}catch(c){return c}}parse(a){let c=a[0];switch(this._step){case 1:if(this._protocol._server){if(c!==lt.KEXDH_INIT)return Ye(this._protocol,`Received packet ${c} instead of ${lt.KEXDH_INIT}`,"handshake",Ge.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH Init"),Ve.init(a,1);let f=Ve.readString();if(Ve.clear(),f===void 0)return Ye(this._protocol,"Received malformed KEX*_INIT","handshake",Ge.KEY_EXCHANGE_FAILED);this._dhData=f;let l=this._protocol._hostKeys[this.negotiated.serverHostKey];Array.isArray(l)&&(l=l[0]),this._hostKey=l,this.finish()}else{if(c!==lt.KEXDH_REPLY)return Ye(this._protocol,`Received packet ${c} instead of ${lt.KEXDH_REPLY}`,"handshake",Ge.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH Reply"),Ve.init(a,1);let f,l,u;if((f=Ve.readString())===void 0||(l=Ve.readString())===void 0||(u=Ve.readString())===void 0)return Ve.clear(),Ye(this._protocol,"Received malformed KEX*_REPLY","handshake",Ge.KEY_EXCHANGE_FAILED);Ve.clear(),Ve.init(f,0);let h=Ve.readString(!0);if(Ve.clear(),h===void 0)return Ye(this._protocol,"Received malformed host public key","handshake",Ge.KEY_EXCHANGE_FAILED);if(h!==this.negotiated.serverHostKey)switch(this.negotiated.serverHostKey){case"rsa-sha2-256":case"rsa-sha2-512":if(h==="ssh-rsa")break;default:return Ye(this._protocol,"Host key does not match negotiated type","handshake",Ge.KEY_EXCHANGE_FAILED)}this._hostKey=f,this._dhData=l,this._sig=u;let g=!1,y;if(this._protocol._hostVerifier===void 0?(y=!0,this._protocol._debug&&this._protocol._debug("Host accepted by default (no verification)")):y=this._protocol._hostVerifier(f,_=>{if(!g){if(g=!0,_===!1)return this._protocol._debug&&this._protocol._debug("Host denied (verification failed)"),Ye(this._protocol,"Host denied (verification failed)","handshake",Ge.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Host accepted (verified)"),this._hostVerified=!0,this._receivedNEWKEYS?this.finish():Us(this)}}),y===void 0){++this._step;return}if(g=!0,y===!1)return this._protocol._debug&&this._protocol._debug("Host denied (verification failed)"),Ye(this._protocol,"Host denied (verification failed)","handshake",Ge.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Host accepted (verified)"),this._hostVerified=!0,Us(this)}++this._step;break;case 2:return c!==lt.NEWKEYS?Ye(this._protocol,`Received packet ${c} instead of ${lt.NEWKEYS}`,"handshake",Ge.KEY_EXCHANGE_FAILED):(this._protocol._debug&&this._protocol._debug("Inbound: NEWKEYS"),this._receivedNEWKEYS=!0,this._protocol._strictMode&&(this._protocol._decipher.inSeqno=0),++this._step,this.finish(!this._protocol._server&&!this._hostVerified));default:return Ye(this._protocol,`Received unexpected packet ${c} after NEWKEYS`,"handshake",Ge.KEY_EXCHANGE_FAILED)}}}class e extends t{constructor(a,...c){super(...c),this.type="25519",this.hashName=a,this._keys=null}generateKeys(){this._keys||(this._keys=g0("x25519"))}getPublicKey(){return this.generateKeys(),this._keys.publicKey.export({type:"spki",format:"der"}).slice(-32)}convertPublicKey(a){let c,f=0,l=a.length;for(;a[f]===0;)++f,--l;return a.length===32||l!==a.length&&(c=Buffer.allocUnsafe(l),a.copy(c,0,f),a=c),a}computeSecret(a){this.generateKeys();try{let c=new sd.Writer;return c.startSequence(),c.startSequence(),c.writeOID("1.3.101.110"),c.endSequence(),c.startSequence(sd.BitString),c.writeByte(0),c._ensure(a.length),a.copy(c._buf,c._offset,0,a.length),c._offset+=a.length,c.endSequence(),c.endSequence(),n(p0({privateKey:this._keys.privateKey,publicKey:h0({key:c.buffer,type:"spki",format:"der"})}))}catch(c){return c}}}class r extends t{constructor(a,c,...f){super(...f),this.type="ecdh",this.curveName=a,this.hashName=c}generateKeys(){this._dh||(this._dh=d0(this.curveName),this._public=this._dh.generateKeys())}}class s extends t{constructor(a,...c){super(...c),this.type="groupex",this.hashName=a,this._prime=null,this._generator=null,this._minBits=I0,this._prefBits=B0(this.negotiated),this._protocol._compatFlags&Ra.BUG_DHGEX_LARGE&&(this._prefBits=Math.min(this._prefBits,4096)),this._maxBits=C0}start(){if(this._protocol._server)return;this._protocol._debug&&this._protocol._debug("Outbound: Sending KEXDH_GEX_REQUEST");let a=this._protocol._packetRW.write.allocStartKEX,c=this._protocol._packetRW.write.alloc(13,!0);c[a]=lt.KEXDH_GEX_REQUEST,Mt(c,this._minBits,++a),Mt(c,this._prefBits,a+=4),Mt(c,this._maxBits,a+=4),this._protocol._cipher.encrypt(this._protocol._packetRW.write.finalize(c,!0))}generateKeys(){!this._dh&&this._prime&&this._generator&&(this._dh=l0(this._prime,this._generator),this._public=this._dh.generateKeys())}setDHParams(a,c){if(!Buffer.isBuffer(a))throw new Error("Invalid prime value");if(!Buffer.isBuffer(c))throw new Error("Invalid generator value");this._prime=a,this._generator=c}getDHParams(){if(this._dh)return{prime:n(this._dh.getPrime()),generator:n(this._dh.getGenerator())}}parse(a){let c=a[0];switch(this._step){case 1:{if(this._protocol._server)return c!==lt.KEXDH_GEX_REQUEST?Ye(this._protocol,`Received packet ${c} instead of `+lt.KEXDH_GEX_REQUEST,"handshake",Ge.KEY_EXCHANGE_FAILED):Ye(this._protocol,"Group exchange not implemented for server","handshake",Ge.KEY_EXCHANGE_FAILED);if(c!==lt.KEXDH_GEX_GROUP)return Ye(this._protocol,`Received packet ${c} instead of ${lt.KEXDH_GEX_GROUP}`,"handshake",Ge.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH GEX Group"),Ve.init(a,1);let f,l;if((f=Ve.readString())===void 0||(l=Ve.readString())===void 0)return Ve.clear(),Ye(this._protocol,"Received malformed KEXDH_GEX_GROUP","handshake",Ge.KEY_EXCHANGE_FAILED);Ve.clear(),this.setDHParams(f,l),this.generateKeys();let u=this.getPublicKey();this._protocol._debug&&this._protocol._debug("Outbound: Sending KEXDH_GEX_INIT");let h=this._protocol._packetRW.write.allocStartKEX,g=this._protocol._packetRW.write.alloc(5+u.length,!0);g[h]=lt.KEXDH_GEX_INIT,Mt(g,u.length,++h),g.set(u,h+=4),this._protocol._cipher.encrypt(this._protocol._packetRW.write.finalize(g,!0)),++this._step;break}case 2:if(this._protocol._server)return c!==lt.KEXDH_GEX_INIT?Ye(this._protocol,`Received packet ${c} instead of ${lt.KEXDH_GEX_INIT}`,"handshake",Ge.KEY_EXCHANGE_FAILED):(this._protocol._debug&&this._protocol._debug("Received DH GEX Init"),Ye(this._protocol,"Group exchange not implemented for server","handshake",Ge.KEY_EXCHANGE_FAILED));if(c!==lt.KEXDH_GEX_REPLY)return Ye(this._protocol,`Received packet ${c} instead of ${lt.KEXDH_GEX_REPLY}`,"handshake",Ge.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH GEX Reply"),this._step=1,a[0]=lt.KEXDH_REPLY,this.parse=t.prototype.parse,this.parse(a)}}}class i extends t{constructor(a,c,...f){super(...f),this.type="group",this.groupName=a,this.hashName=c}start(){if(!this._protocol._server){this._protocol._debug&&this._protocol._debug("Outbound: Sending KEXDH_INIT");let a=this.getPublicKey(),c=this._protocol._packetRW.write.allocStartKEX,f=this._protocol._packetRW.write.alloc(5+a.length,!0);f[c]=lt.KEXDH_INIT,Mt(f,a.length,++c),f.set(a,c+=4),this._protocol._cipher.encrypt(this._protocol._packetRW.write.finalize(f,!0))}}generateKeys(){this._dh||(this._dh=u0(this.groupName),this._public=this._dh.generateKeys())}getDHParams(){if(this._dh)return{prime:n(this._dh.getPrime()),generator:n(this._dh.getGenerator())}}}return(o,...a)=>{if(typeof o!="object"||o===null)throw new Error("Invalid negotiated argument");let c=o.kex;if(typeof c=="string"){switch(a=[o,...a],c){case"curve25519-sha256":case"curve25519-sha256@libssh.org":if(!A0)break;return new e("sha256",...a);case"ecdh-sha2-nistp256":return new r("prime256v1","sha256",...a);case"ecdh-sha2-nistp384":return new r("secp384r1","sha384",...a);case"ecdh-sha2-nistp521":return new r("secp521r1","sha512",...a);case"diffie-hellman-group1-sha1":return new i("modp2","sha1",...a);case"diffie-hellman-group14-sha1":return new i("modp14","sha1",...a);case"diffie-hellman-group14-sha256":return new i("modp14","sha256",...a);case"diffie-hellman-group15-sha512":return new i("modp15","sha512",...a);case"diffie-hellman-group16-sha512":return new i("modp16","sha512",...a);case"diffie-hellman-group17-sha512":return new i("modp17","sha512",...a);case"diffie-hellman-group18-sha512":return new i("modp18","sha512",...a);case"diffie-hellman-group-exchange-sha1":return new s("sha1",...a);case"diffie-hellman-group-exchange-sha256":return new s("sha256",...a)}throw new Error(`Unsupported key exchange algorithm: ${c}`)}throw new Error(`Invalid key exchange type: ${c}`)}})(),ka=(()=>{let n=["kex","serverHostKey",["cs","cipher"],["sc","cipher"],["cs","mac"],["sc","mac"],["cs","compress"],["sc","compress"],["cs","lang"],["sc","lang"]];return class{constructor(e){if(typeof e!="object"||e===null)throw new TypeError("Argument must be an object");let r={kex:void 0,serverHostKey:void 0,cs:{cipher:void 0,mac:void 0,compress:void 0,lang:void 0},sc:{cipher:void 0,mac:void 0,compress:void 0,lang:void 0},all:void 0},s=0;for(let a of n){let c,f,l,u;if(typeof a=="string")c=r,f=e[a],l=u=a;else{let g=a[0];c=r[g],u=a[1],f=e[g][u],l=`${g}.${u}`}let h={array:void 0,buffer:void 0};if(Buffer.isBuffer(f))h.array=(""+f).split(","),h.buffer=f,s+=4+f.length;else{if(typeof f=="string"&&(f=f.split(",")),Array.isArray(f))h.array=f,h.buffer=Buffer.from(f.join(","));else throw new TypeError(`Invalid \`${l}\` type: ${typeof f}`);s+=4+h.buffer.length}c[u]=h}let i=Buffer.allocUnsafe(s);r.all=i;let o=0;for(let a of n){let c;typeof a=="string"?c=r[a].buffer:c=r[a[0]][a[1]].buffer,o=Mt(i,c.length,o),i.set(c,o),o+=c.length}this.totalSize=s,this.lists=r}copyAllTo(e,r){let s=this.lists.all;if(typeof r!="number")throw new TypeError(`Invalid offset value: ${typeof r}`);if(e.length-r<s.length)throw new Error("Insufficient space to copy list");return e.set(s,r),s.length}}})(),Cn=(()=>{let n=Buffer.allocUnsafe(4);return(t,e)=>{Mt(n,e.length,0),t.update(n),t.update(e)}})();function Hr(n,t,e,r,s,i){let o;if(n){let a=Ba(t).update(e).update(r).update(i).update(s).digest();for(;a.length<n;){let c=Ba(t).update(e).update(r).update(a).digest(),f=Buffer.allocUnsafe(a.length+c.length);f.set(a,0),f.set(c,a.length),a=f}a.length===n?o=a:o=new S0(a.buffer,a.byteOffset,n)}else o=v0;return o}function hd(n,t){if(t.length===0){this._debug&&this._debug("Inbound: Skipping empty packet payload");return}if(this._skipNextInboundPacket){this._skipNextInboundPacket=!1;return}t=this._packetRW.read.read(t);let e=t[0];if(!this._strictMode)switch(e){case lt.IGNORE:case lt.UNIMPLEMENTED:case lt.DEBUG:return Fr||(Fr=ks()),Fr[e](this,t)}switch(e){case lt.DISCONNECT:return Fr||(Fr=ks()),Fr[e](this,t);case lt.KEXINIT:return n.firstPacket?(n.firstPacket=!1,dd(this,t)):Ye(this,"Received extra KEXINIT during handshake","handshake",Ge.KEY_EXCHANGE_FAILED);default:if(e<20||e>49)return Ye(this,`Received unexpected packet type ${e}`,"handshake",Ge.KEY_EXCHANGE_FAILED)}return this._kex.parse(t)}function B0(n){let t=Qr[n.cs.cipher],e=Qr[n.sc.cipher],r=Math.max(0,t.sslName==="des-ede3-cbc"?14:t.keyLen,t.blockLen,t.ivLen,e.sslName==="des-ede3-cbc"?14:e.keyLen,e.blockLen,e.ivLen)*8;return r<=112?2048:r<=128?3072:r<=192?7680:8192}function Us(n){if(!n._sentNEWKEYS){n._protocol._debug&&n._protocol._debug("Outbound: Sending NEWKEYS");let t=n._protocol._packetRW.write.allocStartKEX,e=n._protocol._packetRW.write.alloc(1,!0);e[t]=lt.NEWKEYS,n._protocol._cipher.encrypt(n._protocol._packetRW.write.finalize(e,!0)),n._sentNEWKEYS=!0,n._protocol._strictMode&&(n._protocol._cipher.outSeqno=0)}}pd.exports={KexInit:ka,kexinit:ud,onKEXPayload:hd,DEFAULT_KEXINIT_CLIENT:new ka({kex:od.concat(["ext-info-c","kex-strict-c-v00@openssh.com"]),serverHostKey:ad,cs:{cipher:Rs,mac:Ns,compress:Ps,lang:[]},sc:{cipher:Rs,mac:Ns,compress:Ps,lang:[]}}),DEFAULT_KEXINIT_SERVER:new ka({kex:od.concat(["kex-strict-s-v00@openssh.com"]),serverHostKey:ad,cs:{cipher:Rs,mac:Ns,compress:Ps,lang:[]},sc:{cipher:Rs,mac:Ns,compress:Ps,lang:[]}}),HANDLERS:{[lt.KEXINIT]:dd}}});var gd=at((Yx,R0)=>{R0.exports={name:"ssh2",version:"1.17.0",author:"Brian White <mscdex@mscdex.net>",description:"SSH2 client and server modules written in pure JavaScript for node.js",main:"./lib/index.js",engines:{node:">=10.16.0"},dependencies:{asn1:"^0.2.6","bcrypt-pbkdf":"^1.0.2"},devDependencies:{"@mscdex/eslint-config":"^1.1.0",eslint:"^7.32.0"},optionalDependencies:{"cpu-features":"~0.0.10",nan:"^2.23.0"},scripts:{install:"node install.js",rebuild:"node install.js",test:"node test/test.js",lint:"eslint --cache --report-unused-disable-directives --ext=.js .eslintrc.js examples lib test","lint:fix":"npm run lint -- --fix"},keywords:["ssh","ssh2","sftp","secure","shell","exec","remote","client"],licenses:[{type:"MIT",url:"http://github.com/mscdex/ssh2/raw/master/LICENSE"}],repository:{type:"git",url:"http://github.com/mscdex/ssh2.git"}}});var La=at((zx,kd)=>{"use strict";var{inspect:bd}=require("util"),{bindingAvailable:N0,NullCipher:P0,NullDecipher:T0}=Kn(),{COMPAT_CHECKS:L0,DISCONNECT_REASON:xd,eddsaSupported:U0,MESSAGE:Se,SIGNALS:md,TERMINAL_MODE:Pa}=Ln(),{DEFAULT_KEXINIT_CLIENT:D0,DEFAULT_KEXINIT_SERVER:O0,KexInit:Ad,kexinit:Sd,onKEXPayload:M0}=Bs(),{parseKey:Ed}=Yn(),$0=ks(),{bufferCopy:Ds,bufferFill:F0,bufferSlice:wd,convertSignature:_d,sendPacket:we,writeUInt32BE:B}=hn(),{PacketReader:H0,PacketWriter:Q0,ZlibPacketReader:Id,ZlibPacketWriter:Cd}=Ia(),W0=gd().version,q0=new Map(Object.values(xd).map(n=>[n,1])),vd=Buffer.from(`SSH-2.0-ssh2js${W0}`),K0=Buffer.from(`${vd}\r
|
|
7
|
-
`),
|
|
6
|
+
${e}-----END ${n} KEY-----`}function ui(n,t){let e=Buffer.allocUnsafe(n.length+t.length);return e.set(n,0),e.set(t,n.length),e}function Wo(n,t){let e=n.length,r=n._pos||0;for(let s=0;s<t;++s){let i=e-r;if(r>=e||i<4)return!1;let o=ci(n,r);if(i<4+o)return!1;r+=4+o}return n._pos=r,!0}function di(n,t){let e=new Be.Writer;return e.startSequence(),e.startSequence(),e.writeOID("1.2.840.113549.1.1.1"),e.writeNull(),e.endSequence(),e.startSequence(Be.BitString),e.writeByte(0),e.startSequence(),e.writeBuffer(n,Be.Integer),e.writeBuffer(t,Be.Integer),e.endSequence(),e.endSequence(),e.endSequence(),pn("PUBLIC",e.buffer)}function hi(n,t){let e=Buffer.allocUnsafe(15+t.length+4+n.length);Dt(e,7,0),e.utf8Write("ssh-rsa",4,7);let r=11;return Dt(e,t.length,r),e.set(t,r+=4),Dt(e,n.length,r+=t.length),e.set(n,r+4),e}var Jc=(()=>{function n(r,s,i,o,a,c,f,l){let u=new Be.Writer;return u.startSequence(),u.writeInt(0,Be.Integer),u.writeBuffer(r,Be.Integer),u.writeBuffer(s,Be.Integer),u.writeBuffer(i,Be.Integer),u.writeBuffer(o,Be.Integer),u.writeBuffer(a,Be.Integer),u.writeBuffer(c,Be.Integer),u.writeBuffer(f,Be.Integer),u.writeBuffer(l,Be.Integer),u.endSequence(),u.buffer}function t(r){return BigInt(`0x${r.hexSlice(0,r.length)}`)}function e(r){let s=r.toString(16);if((s.length&1)!==0)s=`0${s}`;else{let i=s.charCodeAt(0);(i===56||i===57||i>=97&&i<=102)&&(s=`00${s}`)}return Buffer.from(s,"hex")}return function(s,i,o,a,c,f){let l=t(o),u=e(l%(t(c)-1n)),h=e(l%(t(f)-1n));return pn("RSA PRIVATE",n(s,i,o,c,f,u,h,a))}})();function pi(n,t,e,r){let s=new Be.Writer;return s.startSequence(),s.startSequence(),s.writeOID("1.2.840.10040.4.1"),s.startSequence(),s.writeBuffer(n,Be.Integer),s.writeBuffer(t,Be.Integer),s.writeBuffer(e,Be.Integer),s.endSequence(),s.endSequence(),s.startSequence(Be.BitString),s.writeByte(0),s.writeBuffer(r,Be.Integer),s.endSequence(),s.endSequence(),pn("PUBLIC",s.buffer)}function gi(n,t,e,r){let s=Buffer.allocUnsafe(15+n.length+4+t.length+4+e.length+4+r.length);Dt(s,7,0),s.utf8Write("ssh-dss",4,7);let i=11;return Dt(s,n.length,i),s.set(n,i+=4),Dt(s,t.length,i+=n.length),s.set(t,i+=4),Dt(s,e.length,i+=t.length),s.set(e,i+=4),Dt(s,r.length,i+=e.length),s.set(r,i+4),s}function Zc(n,t,e,r,s){let i=new Be.Writer;return i.startSequence(),i.writeInt(0,Be.Integer),i.writeBuffer(n,Be.Integer),i.writeBuffer(t,Be.Integer),i.writeBuffer(e,Be.Integer),i.writeBuffer(r,Be.Integer),i.writeBuffer(s,Be.Integer),i.endSequence(),pn("DSA PRIVATE",i.buffer)}function ef(n){let t=new Be.Writer;return t.startSequence(),t.startSequence(),t.writeOID("1.3.101.112"),t.endSequence(),t.startSequence(Be.BitString),t.writeByte(0),t._ensure(n.length),t._buf.set(n,t._offset),t._offset+=n.length,t.endSequence(),t.endSequence(),pn("PUBLIC",t.buffer)}function tf(n){let t=Buffer.allocUnsafe(19+n.length);return Dt(t,11,0),t.utf8Write("ssh-ed25519",4,11),Dt(t,n.length,15),t.set(n,19),t}function wp(n){let t=new Be.Writer;return t.startSequence(),t.writeInt(0,Be.Integer),t.startSequence(),t.writeOID("1.3.101.112"),t.endSequence(),t.startSequence(Be.OctetString),t.writeBuffer(n,Be.OctetString),t.endSequence(),t.endSequence(),pn("PRIVATE",t.buffer)}function qo(n,t){let e=new Be.Writer;return e.startSequence(),e.startSequence(),e.writeOID("1.2.840.10045.2.1"),e.writeOID(n),e.endSequence(),e.startSequence(Be.BitString),e.writeByte(0),e._ensure(t.length),e._buf.set(t,e._offset),e._offset+=t.length,e.endSequence(),e.endSequence(),pn("PUBLIC",e.buffer)}function Ko(n,t){let e;switch(n){case"1.2.840.10045.3.1.7":e="nistp256";break;case"1.3.132.0.34":e="nistp384";break;case"1.3.132.0.35":e="nistp521";break;default:return}let r=Buffer.allocUnsafe(39+t.length);return Dt(r,19,0),r.utf8Write(`ecdsa-sha2-${e}`,4,19),Dt(r,8,23),r.utf8Write(e,27,8),Dt(r,t.length,35),r.set(t,39),r}function Ip(n,t,e){let r=new Be.Writer;return r.startSequence(),r.writeInt(1,Be.Integer),r.writeBuffer(e,Be.OctetString),r.startSequence(160),r.writeOID(n),r.endSequence(),r.startSequence(161),r.startSequence(Be.BitString),r.writeByte(0),r._ensure(t.length),r._buf.set(t,r._offset),r._offset+=t.length,r.endSequence(),r.endSequence(),r.endSequence(),pn("EC PRIVATE",r.buffer)}function Cp(n,t){let e=gp(n);return e.setPrivateKey(t),e.getPublicKey()}var mi={sign:typeof jc=="function"?function(t,e){let r=this[hn];if(r===null)return new Error("No private key available");(!e||typeof e!="string")&&(e=this[Tn]);try{return jc(e,t,r)}catch(s){return s}}:function(t,e){let r=this[hn];if(r===null)return new Error("No private key available");(!e||typeof e!="string")&&(e=this[Tn]);let s=Ap(e);s.update(t);try{return s.sign(r)}catch(i){return i}},verify:typeof Xc=="function"?function(t,e,r){let s=this[_n];if(s===null)return new Error("No public key available");(!r||typeof r!="string")&&(r=this[Tn]);try{return Xc(r,t,s,e)}catch(i){return i}}:function(t,e,r){let s=this[_n];if(s===null)return new Error("No public key available");(!r||typeof r!="string")&&(r=this[Tn]);let i=Ep(r);i.update(t);try{return i.verify(s,e)}catch(o){return o}},isPrivateKey:function(){return this[hn]!==null},getPrivatePEM:function(){return this[hn]},getPublicPEM:function(){return this[_n]},getPublicSSH:function(){return this[qn]},equals:function(t){let e=sf(t);return e instanceof Error?!1:this.type===e.type&&this[hn]===e[hn]&&this[_n]===e[_n]&&this[qn].equals(e[qn])}};function ss(n,t,e,r,s,i,o){this.type=n,this.comment=t,this[hn]=e,this[_n]=r,this[qn]=s,this[Tn]=i,this[Br]=o}ss.prototype=mi;{let t=function(e,r,s){let i=[];if(e.length<8)return new Error("Malformed OpenSSH private key");let o=ci(e,0),a=ci(e,4);if(o!==a)return s?new Error("OpenSSH key integrity check failed -- bad passphrase?"):new Error("OpenSSH key integrity check failed");e._pos=8;let c,f;for(c=0;c<r;++c){let u,h,g,y,_=ve(e,e._pos,!0);if(_===void 0)return new Error("Malformed OpenSSH private key");switch(_){case"ssh-rsa":{let C=ve(e,e._pos);if(C===void 0)return new Error("Malformed OpenSSH private key");let L=ve(e,e._pos);if(L===void 0)return new Error("Malformed OpenSSH private key");let F=ve(e,e._pos);if(F===void 0)return new Error("Malformed OpenSSH private key");let k=ve(e,e._pos);if(k===void 0)return new Error("Malformed OpenSSH private key");let K=ve(e,e._pos);if(K===void 0)return new Error("Malformed OpenSSH private key");let ee=ve(e,e._pos);if(ee===void 0)return new Error("Malformed OpenSSH private key");g=di(C,L),y=hi(C,L),h=Jc(C,L,F,k,K,ee),u="sha1";break}case"ssh-dss":{let C=ve(e,e._pos);if(C===void 0)return new Error("Malformed OpenSSH private key");let L=ve(e,e._pos);if(L===void 0)return new Error("Malformed OpenSSH private key");let F=ve(e,e._pos);if(F===void 0)return new Error("Malformed OpenSSH private key");let k=ve(e,e._pos);if(k===void 0)return new Error("Malformed OpenSSH private key");let K=ve(e,e._pos);if(K===void 0)return new Error("Malformed OpenSSH private key");g=pi(C,L,F,k),y=gi(C,L,F,k),h=Zc(C,L,F,k,K),u="sha1";break}case"ssh-ed25519":{if(!Qo)return new Error(`Unsupported OpenSSH private key type: ${_}`);let C=ve(e,e._pos);if(C===void 0||C.length!==32)return new Error("Malformed OpenSSH private key");let L=ve(e,e._pos);if(L===void 0||L.length!==64)return new Error("Malformed OpenSSH private key");g=ef(C),y=tf(C),h=wp(ar(L,0,32)),u=null;break}case"ecdsa-sha2-nistp256":u="sha256",f="1.2.840.10045.3.1.7";case"ecdsa-sha2-nistp384":u===void 0&&(u="sha384",f="1.3.132.0.34");case"ecdsa-sha2-nistp521":{if(u===void 0&&(u="sha512",f="1.3.132.0.35"),!Wo(e,1))return new Error("Malformed OpenSSH private key");let C=ve(e,e._pos);if(C===void 0)return new Error("Malformed OpenSSH private key");let L=ve(e,e._pos);if(L===void 0)return new Error("Malformed OpenSSH private key");g=qo(f,C),y=Ko(f,C),h=Ip(f,C,L);break}default:return new Error(`Unsupported OpenSSH private key type: ${_}`)}let b=ve(e,e._pos,!0);if(b===void 0)return new Error("Malformed OpenSSH private key");i.push(new ss(_,b,h,g,y,u,s))}let l=0;for(c=e._pos;c<e.length;++c)if(e[c]!==++l%255)return new Error("Malformed OpenSSH private key");return i},n=/^-----BEGIN OPENSSH PRIVATE KEY-----(?:\r\n|\n)([\s\S]+)(?:\r\n|\n)-----END OPENSSH PRIVATE KEY-----$/;ss.parse=(e,r)=>{let s=n.exec(e);if(s===null)return null;let i,o=Buffer.from(s[1],"base64");if(o.length<31)return new Error("Malformed OpenSSH private key");let a=o.utf8Slice(0,15);if(a!=="openssh-key-v1\0")return new Error(`Unsupported OpenSSH key magic: ${a}`);let c=ve(o,15,!0);if(c===void 0)return new Error("Malformed OpenSSH private key");if(c!=="none"&&xp.indexOf(c)===-1)return new Error(`Unsupported cipher for OpenSSH key: ${c}`);let f=ve(o,o._pos,!0);if(f===void 0)return new Error("Malformed OpenSSH private key");if(f!=="none"){if(c==="none")return new Error("Malformed OpenSSH private key");if(f!=="bcrypt")return new Error(`Unsupported kdf name for OpenSSH key: ${f}`);if(!r)return new Error("Encrypted private OpenSSH key detected, but no passphrase given")}else if(c!=="none")return new Error("Malformed OpenSSH private key");let l,u,h;c!=="none"&&(l=li[c]);let g=ve(o,o._pos);if(g===void 0)return new Error("Malformed OpenSSH private key");if(g.length)switch(f){case"none":return new Error("Malformed OpenSSH private key");case"bcrypt":{let _=ve(g,0);if(_===void 0||g._pos+4>g.length)return new Error("Malformed OpenSSH private key");let b=ci(g,g._pos),C=Buffer.allocUnsafe(l.keyLen+l.ivLen);if(bp(r,r.length,_,_.length,C,C.length,b)!==0)return new Error("Failed to generate information to decrypt key");u=ar(C,0,l.keyLen),h=ar(C,l.keyLen,C.length);break}}else if(f!=="none")return new Error("Malformed OpenSSH private key");if(o._pos+3>=o.length)return new Error("Malformed OpenSSH private key");let y=ci(o,o._pos);if(o._pos+=4,y>0){for(let b=0;b<y;++b){let C=ve(o,o._pos);if(C===void 0)return new Error("Malformed OpenSSH private key");if(ve(C,0,!0)===void 0)return new Error("Malformed OpenSSH private key")}let _=ve(o,o._pos);if(_===void 0)return new Error("Malformed OpenSSH private key");if(u!==void 0){if(_.length<l.blockLen||_.length%l.blockLen!==0)return new Error("Malformed OpenSSH private key");try{let b={authTagLength:l.authLen},C=Ho(l.sslName,u,h,b);if(C.setAutoPadding(!1),l.authLen>0){if(o.length-o._pos<l.authLen)return new Error("Malformed OpenSSH private key");C.setAuthTag(ar(o,o._pos,o._pos+=l.authLen))}_=ui(C.update(_),C.final())}catch(b){return b}}if(o._pos!==o.length)return new Error("Malformed OpenSSH private key");i=t(_,y,u!==void 0)}else i=[];return i instanceof Error?i:i[0]}}function os(n,t,e,r,s,i,o){this.type=n,this.comment=t,this[hn]=e,this[_n]=r,this[qn]=s,this[Tn]=i,this[Br]=o}os.prototype=mi;{let n=/^-----BEGIN (RSA|DSA|EC) PRIVATE KEY-----(?:\r\n|\n)((?:[^:]+:\s*[\S].*(?:\r\n|\n))*)([\s\S]+)(?:\r\n|\n)-----END (RSA|DSA|EC) PRIVATE KEY-----$/;os.parse=(t,e)=>{let r=n.exec(t);if(r===null)return null;let s=Buffer.from(r[3],"base64"),i=r[2],o=!1;if(i!==void 0){i=i.split(/\r\n|\n/g);for(let y=0;y<i.length;++y){let _=i[y],b=_.indexOf(":");if(_.slice(0,b)==="DEK-Info"){let C=_.slice(b+2);if(b=C.indexOf(","),b===-1)continue;let L=C.slice(0,b).toLowerCase();if(yp.indexOf(L)===-1)return new Error(`Cipher (${L}) not supported for encrypted OpenSSH private key`);let F=Fo[L];if(!F)return new Error(`Cipher (${L}) not supported for encrypted OpenSSH private key`);let k=Buffer.from(C.slice(b+1),"hex");if(k.length!==F.ivLen)return new Error("Malformed encrypted OpenSSH private key");if(!e)return new Error("Encrypted OpenSSH private key detected, but no passphrase given");let K=ar(k,0,8),ee=fi("md5").update(e).update(K).digest();for(;ee.length<F.keyLen;)ee=ui(ee,fi("md5").update(ee).update(e).update(K).digest());ee.length>F.keyLen&&(ee=ar(ee,0,F.keyLen));try{let O=Ho(L,ee,k);O.setAutoPadding(!1),s=ui(O.update(s),O.final()),o=!0}catch(O){return O}}}}let a,c,f,l,u,h,g="Malformed OpenSSH private key";switch(o&&(g+=". Bad passphrase?"),r[1]){case"RSA":a="ssh-rsa",c=pn("RSA PRIVATE",s);try{h=new Be.Reader(s),h.readSequence(),h.readInt();let y=h.readString(Be.Integer,!0);if(y===null)return new Error(g);let _=h.readString(Be.Integer,!0);if(_===null)return new Error(g);f=di(y,_),l=hi(y,_)}catch{return new Error(g)}u="sha1";break;case"DSA":a="ssh-dss",c=pn("DSA PRIVATE",s);try{h=new Be.Reader(s),h.readSequence(),h.readInt();let y=h.readString(Be.Integer,!0);if(y===null)return new Error(g);let _=h.readString(Be.Integer,!0);if(_===null)return new Error(g);let b=h.readString(Be.Integer,!0);if(b===null)return new Error(g);let C=h.readString(Be.Integer,!0);if(C===null)return new Error(g);f=pi(y,_,b,C),l=gi(y,_,b,C)}catch{return new Error(g)}u="sha1";break;case"EC":{let y,_,b;try{h=new Be.Reader(s),h.readSequence(),h.readInt(),_=h.readString(Be.OctetString,!0),h.readByte();let L=h.readLength();if(L!==null){if(h._offset=L,b=h.readOID(),b===null)return new Error(g);switch(b){case"1.2.840.10045.3.1.7":y="prime256v1",a="ecdsa-sha2-nistp256",u="sha256";break;case"1.3.132.0.34":y="secp384r1",a="ecdsa-sha2-nistp384",u="sha384";break;case"1.3.132.0.35":y="secp521r1",a="ecdsa-sha2-nistp521",u="sha512";break;default:return new Error(`Unsupported private key EC OID: ${b}`)}}else return new Error(g)}catch{return new Error(g)}c=pn("EC PRIVATE",s);let C=Cp(y,_);f=qo(b,C),l=Ko(b,C);break}}return new os(a,"",c,f,l,u,o)}}function as(n,t,e,r,s,i,o){this.type=n,this.comment=t,this[hn]=e,this[_n]=r,this[qn]=s,this[Tn]=i,this[Br]=o}as.prototype=mi;{let n=Buffer.alloc(0),t=Buffer.from([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),e=Buffer.from([0,0,0,0]),r=Buffer.from([0,0,0,1]),s=/^PuTTY-User-Key-File-2: (ssh-(?:rsa|dss))\r?\nEncryption: (aes256-cbc|none)\r?\nComment: ([^\r\n]*)\r?\nPublic-Lines: \d+\r?\n([\s\S]+?)\r?\nPrivate-Lines: \d+\r?\n([\s\S]+?)\r?\nPrivate-MAC: ([^\r\n]+)/;as.parse=(i,o)=>{let a=s.exec(i);if(a===null)return null;let c=a[2],f=c!=="none";if(f&&!o)return new Error("Encrypted PPK private key detected, but no passphrase given");let l=Buffer.from(a[5],"base64");if(f){let I=li[c],U=ui(fi("sha1").update(e).update(o).digest(),fi("sha1").update(r).update(o).digest());U.length>I.keyLen&&(U=ar(U,0,I.keyLen));try{let R=Ho(I.sslName,U,t);R.setAutoPadding(!1),l=ui(R.update(l),R.final())}catch(R){return R}}let u=a[1],h=a[3],g=Buffer.from(a[4],"base64"),y=a[6],_=u.length,b=c.length,C=Buffer.byteLength(h),L=g.length,F=l.length,k=Buffer.allocUnsafe(4+_+4+b+4+C+4+L+4+F),K=0;if(Dt(k,_,K),k.utf8Write(u,K+=4,_),Dt(k,b,K+=_),k.utf8Write(c,K+=4,b),Dt(k,C,K+=b),k.utf8Write(h,K+=4,C),Dt(k,L,K+=C),k.set(g,K+=4),Dt(k,F,K+=L),k.set(l,K+4),o||(o=n),mp("sha1",fi("sha1").update("putty-private-key-file-mac-key").update(o).digest()).update(k).digest("hex")!==y)return f?new Error("PPK private key integrity check failed -- bad passphrase?"):new Error("PPK private key integrity check failed");let O,x,w;switch(g._pos=0,Wo(g,1),u){case"ssh-rsa":{let I=ve(g,g._pos);if(I===void 0)return new Error("Malformed PPK public key");let U=ve(g,g._pos);if(U===void 0)return new Error("Malformed PPK public key");let R=ve(l,0);if(R===void 0)return new Error("Malformed PPK private key");let re=ve(l,l._pos);if(re===void 0)return new Error("Malformed PPK private key");let G=ve(l,l._pos);if(G===void 0)return new Error("Malformed PPK private key");let Y=ve(l,l._pos);if(Y===void 0)return new Error("Malformed PPK private key");O=di(U,I),x=hi(U,I),w=Jc(U,I,R,Y,re,G);break}case"ssh-dss":{let I=ve(g,g._pos);if(I===void 0)return new Error("Malformed PPK public key");let U=ve(g,g._pos);if(U===void 0)return new Error("Malformed PPK public key");let R=ve(g,g._pos);if(R===void 0)return new Error("Malformed PPK public key");let re=ve(g,g._pos);if(re===void 0)return new Error("Malformed PPK public key");let G=ve(l,0);if(G===void 0)return new Error("Malformed PPK private key");O=pi(I,U,R,re),x=gi(I,U,R,re),w=Zc(I,U,R,re,G);break}}return new as(u,h,w,O,x,"sha1",f)}}function fs(n,t,e,r,s){this.type=n,this.comment=t,this[hn]=null,this[_n]=e,this[qn]=r,this[Tn]=s,this[Br]=!1}fs.prototype=mi;{let n;Qo?n=/^(((?:ssh-(?:rsa|dss|ed25519))|ecdsa-sha2-nistp(?:256|384|521))(?:-cert-v0[01]@openssh.com)?) ([A-Z0-9a-z/+=]+)(?:$|\s+([\S].*)?)$/:n=/^(((?:ssh-(?:rsa|dss))|ecdsa-sha2-nistp(?:256|384|521))(?:-cert-v0[01]@openssh.com)?) ([A-Z0-9a-z/+=]+)(?:$|\s+([\S].*)?)$/,fs.parse=t=>{let e=n.exec(t);if(e===null)return null;let r=e[1],s=e[2],i=Buffer.from(e[3],"base64"),o=e[4]||"",a=ve(i,i._pos,!0);return a===void 0||a.indexOf(s)!==0?new Error("Malformed OpenSSH public key"):Vo(i,s,o,r)}}function cs(n,t,e,r,s){this.type=n,this.comment=t,this[hn]=null,this[_n]=e,this[qn]=r,this[Tn]=s,this[Br]=!1}cs.prototype=mi;{let n=/^---- BEGIN SSH2 PUBLIC KEY ----(?:\r?\n)((?:.{0,72}\r?\n)+)---- END SSH2 PUBLIC KEY ----$/,t=/^[A-Z0-9a-z/+=\r\n]+$/,e=/^([\x21-\x39\x3B-\x7E]{1,64}): ((?:[^\\]*\\\r?\n)*[^\r\n]+)\r?\n/gm,r=/\\\r?\n/g;cs.parse=s=>{let i=n.exec(s);if(i===null)return null;let o=i[1],a=0,c="";for(;i=e.exec(o);){let g=i[1],y=i[2].replace(r,"");if(y.length>1024)return e.lastIndex=0,new Error("Malformed RFC4716 public key");a=e.lastIndex,g.toLowerCase()==="comment"&&(c=y,c.length>1&&c.charCodeAt(0)===34&&c.charCodeAt(c.length-1)===34&&(c=c.slice(1,-1)))}let f=o.slice(a);if(!t.test(f))return new Error("Malformed RFC4716 public key");f=Buffer.from(f,"base64");let l=ve(f,0,!0);if(l===void 0)return new Error("Malformed RFC4716 public key");let u=null,h=null;switch(l){case"ssh-rsa":{let g=ve(f,f._pos);if(g===void 0)return new Error("Malformed RFC4716 public key");let y=ve(f,f._pos);if(y===void 0)return new Error("Malformed RFC4716 public key");u=di(y,g),h=hi(y,g);break}case"ssh-dss":{let g=ve(f,f._pos);if(g===void 0)return new Error("Malformed RFC4716 public key");let y=ve(f,f._pos);if(y===void 0)return new Error("Malformed RFC4716 public key");let _=ve(f,f._pos);if(_===void 0)return new Error("Malformed RFC4716 public key");let b=ve(f,f._pos);if(b===void 0)return new Error("Malformed RFC4716 public key");u=pi(g,y,_,b),h=gi(g,y,_,b);break}default:return new Error("Malformed RFC4716 public key")}return new cs(l,c,u,h,"sha1")}}function Vo(n,t,e,r){if(!nf(t))return new Error(`Unsupported OpenSSH public key type: ${t}`);let s,i,o=null,a=null;switch(t){case"ssh-rsa":{let c=ve(n,n._pos||0);if(c===void 0)return new Error("Malformed OpenSSH public key");let f=ve(n,n._pos);if(f===void 0)return new Error("Malformed OpenSSH public key");o=di(f,c),a=hi(f,c),s="sha1";break}case"ssh-dss":{let c=ve(n,n._pos||0);if(c===void 0)return new Error("Malformed OpenSSH public key");let f=ve(n,n._pos);if(f===void 0)return new Error("Malformed OpenSSH public key");let l=ve(n,n._pos);if(l===void 0)return new Error("Malformed OpenSSH public key");let u=ve(n,n._pos);if(u===void 0)return new Error("Malformed OpenSSH public key");o=pi(c,f,l,u),a=gi(c,f,l,u),s="sha1";break}case"ssh-ed25519":{let c=ve(n,n._pos||0);if(c===void 0||c.length!==32)return new Error("Malformed OpenSSH public key");o=ef(c),a=tf(c),s=null;break}case"ecdsa-sha2-nistp256":s="sha256",i="1.2.840.10045.3.1.7";case"ecdsa-sha2-nistp384":s===void 0&&(s="sha384",i="1.3.132.0.34");case"ecdsa-sha2-nistp521":{if(s===void 0&&(s="sha512",i="1.3.132.0.35"),!Wo(n,1))return new Error("Malformed OpenSSH public key");let c=ve(n,n._pos||0);if(c===void 0)return new Error("Malformed OpenSSH public key");o=qo(i,c),a=Ko(i,c);break}default:return new Error(`Unsupported OpenSSH public key type: ${t}`)}return new fs(r,e,o,a,s)}function nf(n){switch(n){case"ssh-rsa":case"ssh-dss":case"ecdsa-sha2-nistp256":case"ecdsa-sha2-nistp384":case"ecdsa-sha2-nistp521":return!0;case"ssh-ed25519":if(Qo)return!0;default:return!1}}function rf(n){return n?typeof n[Br]=="boolean":!1}function sf(n,t){if(rf(n))return n;let e;if(Buffer.isBuffer(n))e=n,n=n.utf8Slice(0,n.length).trim();else if(typeof n=="string")n=n.trim();else return new Error("Key data must be a Buffer or string");if(t!=null){if(typeof t=="string")t=Buffer.from(t);else if(!Buffer.isBuffer(t))return new Error("Passphrase must be a string or Buffer when supplied")}let r;if((r=ss.parse(n,t))!==null||(r=os.parse(n,t))!==null||(r=as.parse(n,t))!==null||(r=fs.parse(n))!==null||(r=cs.parse(n))!==null)return r;if(e){is.init(e,0);let s=is.readString(!0);s!==void 0&&(n=is.readRaw(),n!==void 0&&(r=Vo(n,s,"",s),r instanceof Error&&(r=null))),is.clear()}return r||new Error("Unsupported key format")}of.exports={isParsedKey:rf,isSupportedKeyType:nf,parseDERKey:(n,t)=>Vo(n,t,"",t),parseKey:sf}});var Jo=at((AE,mf)=>{"use strict";var{Socket:lf}=require("net"),{Duplex:uf}=require("stream"),{resolve:vp}=require("path"),{readFile:af}=require("fs"),{execFile:kp,spawn:Bp}=require("child_process"),{isParsedKey:cf,parseKey:Ai}=Kn(),{makeBufferParser:Rp,readUInt32BE:Xo,writeUInt32BE:Xt,writeUInt32LE:ff}=dn();function Ei(n){let t=!1;return(...e)=>{t||(t=!0,n(...e))}}function Np(n,t){let e=Buffer.allocUnsafe(n.length+t.length);return n.copy(e,0),t.copy(e,n.length),e}function Yo(){}var Pp=Buffer.alloc(0),yt=Rp(),_i=class{getIdentities(t){t(new Error("Missing getIdentities() implementation"))}sign(t,e,r,s){typeof r=="function"&&(s=r),s(new Error("Missing sign() implementation"))}},Nr=class extends _i{constructor(t){super(),this.socketPath=t}getStream(t){t=Ei(t);let e=new lf;e.on("connect",()=>{t(null,e)}),e.on("close",r).on("end",r).on("error",r),e.connect(this.socketPath);function r(){try{e.destroy()}catch{}t(new Error("Failed to connect to agent"))}}getIdentities(t){t=Ei(t),this.getStream((e,r)=>{function s(o){if(r)try{r.destroy()}catch{}o||(o=new Error("Failed to retrieve identities from agent")),t(o)}if(e)return s(e);let i=new zo(!0);i.on("error",s),i.pipe(r).pipe(i),r.on("close",s).on("end",s).on("error",s),i.getIdentities((o,a)=>{if(o)return s(o);try{r.destroy()}catch{}t(null,a)})})}sign(t,e,r,s){typeof r=="function"?(s=r,r=void 0):(typeof r!="object"||r===null)&&(r=void 0),s=Ei(s),this.getStream((i,o)=>{function a(f){if(o)try{o.destroy()}catch{}f||(f=new Error("Failed to sign data with agent")),s(f)}if(i)return a(i);let c=new zo(!0);c.on("error",a),c.pipe(o).pipe(c),o.on("close",a).on("end",a).on("error",a),c.sign(t,e,r,(f,l)=>{if(f)return a(f);try{o.destroy()}catch{}s(null,l)})})}},df=(()=>{let o=vp(__dirname,"..","util/pagent.exe"),a={10:new Error("Invalid pagent.exe arguments"),11:new Error("Pageant is not running"),12:new Error("pagent.exe could not create an mmap"),13:new Error("pagent.exe could not set mode for stdin"),14:new Error("pagent.exe could not set mode for stdout"),15:new Error("pagent.exe did not get expected input payload")};function c(l){l.buffer=null,l.proc&&(l.proc.kill(),l.proc=void 0)}class f extends uf{constructor(){super(),this.proc=void 0,this.buffer=null}_read(u){}_write(u,h,g){if(this.buffer===null)this.buffer=u;else{let C=Buffer.allocUnsafe(this.buffer.length+u.length);this.buffer.copy(C,0),u.copy(C,this.buffer.length),this.buffer=C}if(this.buffer.length<4)return g();let y=Xo(this.buffer,0);if(this.buffer.length-4<y)return g();if(u=this.buffer.slice(0,4+y),this.buffer.length>4+y)return g(new Error("Unexpected multiple agent requests"));this.buffer=null;let _,b=this.proc=Bp(o,[u.length]);b.stdout.on("data",C=>{this.push(C)}),b.on("error",C=>{_=C,g(_)}),b.on("close",C=>{if(this.proc=void 0,!_){if(_=a[C])return g(_);g()}}),b.stdin.end(u)}_final(u){c(this),u()}_destroy(u,h){c(this),h()}}return class extends Nr{getStream(u){u(null,new f)}}})(),hf=(()=>{let n=/^!<socket >(\d+) s ([A-Z0-9]{8}-[A-Z0-9]{8}-[A-Z0-9]{8}-[A-Z0-9]{8})/;return class extends Nr{getStream(e){e=Ei(e);let r=this.socketPath,s=!1;af(r,function i(o,a){if(o){if(s)return e(new Error("Invalid cygwin unix socket path"));kp("cygpath",["-w",r],(ee,O,x)=>{if(ee||O.length===0)return e(new Error("Invalid cygwin unix socket path"));s=!0,r=O.toString().replace(/[\r\n]/g,""),af(r,i)});return}let c=n.exec(a.toString("ascii"));if(!c)return e(new Error("Malformed cygwin unix socket file"));let f,l=0,u=!1,h=[],g,y=Buffer.alloc(12),_=parseInt(c[1],10),b=c[2].replace(/-/g,""),C=Buffer.allocUnsafe(16);for(let ee=0,O=0;O<32;++ee,O+=2)C[ee]=parseInt(b.substring(O,O+2),16);for(let ee=0;ee<16;ee+=4)ff(C,Xo(C,ee),ee);K();function L(){l=0,f="secret",g.write(C)}function F(ee){if(l+=ee.length,f==="secret"){l===16&&(l=0,f="creds",g.write(y));return}if(f==="creds"&&(u||h.push(ee),l===12)){if(g.removeListener("connect",L),g.removeListener("data",F),g.removeListener("error",k),g.removeListener("end",k),g.removeListener("close",k),u)return e(null,g);u=!0,y=Buffer.concat(h),ff(y,process.pid,0),g.on("error",()=>{}),g.destroy(),K()}}function k(){e(new Error("Problem negotiating cygwin unix socket security"))}function K(){g=new lf,g.on("connect",L),g.on("data",F),g.on("error",k),g.on("end",k),g.on("close",k),g.connect(_)}})}}})(),Tp=/^[/\\][/\\]\.[/\\]pipe[/\\].+/;function pf(n){return process.platform==="win32"&&!Tp.test(n)?n==="pageant"?new df:new hf(n):new Nr(n)}var zo=(()=>{function f(x){let w;for(;x[L].length;){let I=x[L][0][u];if(I===void 0)break;x[L].shift(),w=x.push(I)}return w}let l=Symbol("Inbound Request Type"),u=Symbol("Inbound Request Response"),h=Symbol("Inbound Request Context");class g{constructor(w,I){this[l]=w,this[u]=void 0,this[h]=I}hasResponded(){return this[u]!==void 0}getType(){return this[l]}getContext(){return this[h]}}function y(x,w,I){return w[u]=I,f(x)}function _(x){if(x[k]=null,x[F]===0){let w=x[L];if(w&&w.length){x[L]=[];for(let I of w)I.cb(new Error("No reply from server"))}}try{x.end()}catch{}setImmediate(()=>{x[O]||x.emit("end"),x[ee]||x.emit("close")})}function b(){this[ee]=!0}function C(){this[O]=!0}let L=Symbol("Requests"),F=Symbol("Agent Protocol Role"),k=Symbol("Agent Protocol Buffer"),K=Symbol("Agent Protocol Current Message Length"),ee=Symbol("Agent Protocol Closed"),O=Symbol("Agent Protocol Ended");return class extends uf{constructor(w){super({autoDestroy:!0,emitClose:!1}),this[F]=w?0:1,this[L]=[],this[k]=null,this[K]=-1,this.once("end",C),this.once("close",b)}_read(w){}_write(w,I,U){this[k]===null?this[k]=w:this[k]=Np(this[k],w);let R=this[k],re=R.length,G=0;for(;G<re&&!(re<5||(this[K]===-1&&(this[K]=Xo(R,G)),re<4+this[K]));){let Y=R[G+=4];if(++G,this[F]===0){if(this[L].length===0)return U(new Error("Received unexpected message from server"));let te=this[L].shift();switch(Y){case 5:te.cb(new Error("Agent responded with failure"));break;case 12:{if(te.type!==11)return U(new Error("Agent responded with wrong message type"));yt.init(R,G);let ce=yt.readUInt32BE();if(ce===void 0)return yt.clear(),U(new Error("Malformed agent response"));let D=[];for(let v=0;v<ce;++v){let N=yt.readString();if(N===void 0)return yt.clear(),U(new Error("Malformed agent response"));let H=yt.readString(!0);if(H===void 0)return yt.clear(),U(new Error("Malformed agent response"));N=Ai(N),!(N instanceof Error)&&(N.comment=N.comment||H,D.push(N))}G=yt.pos(),yt.clear(),te.cb(null,D);break}case 14:{if(te.type!==13)return U(new Error("Agent responded with wrong message type"));yt.init(R,G);let ce=yt.readString();if(G=yt.pos(),yt.clear(),ce===void 0)return U(new Error("Malformed agent response"));if(yt.init(ce,0),yt.readString(!0),ce=yt.readString(),yt.clear(),ce===void 0)return U(new Error("Malformed OpenSSH signature format"));te.cb(null,ce);break}default:return U(new Error("Agent responded with unsupported message type"))}}else switch(Y){case 11:{let te=new g(Y);this[L].push(te),this.emit("identities",te);break}case 13:{yt.init(R,G);let te=yt.readString(),ce=yt.readString(),D=yt.readUInt32BE();if(G=yt.pos(),yt.clear(),D===void 0){let X=new g(Y);return this[L].push(X),this.failureReply(X)}if(te=Ai(te),te instanceof Error){let X=new g(Y);return this[L].push(X),this.failureReply(X)}let v={hash:void 0},N;te.type==="ssh-rsa"&&(D&2?(N="rsa-sha2-256",v.hash="sha256"):D&4&&(N="rsa-sha2-512",v.hash="sha512")),N===void 0&&(N=te.type);let H=new g(Y,N);this[L].push(H),this.emit("sign",H,te,ce,v);break}default:{let te=new g(Y);this[L].push(te),this.failureReply(te)}}if(this[K]=-1,G===re){this[k]=null;break}else this[k]=R=R.slice(G),re=R.length,G=0}U()}_destroy(w,I){_(this),I()}_final(w){_(this),w()}sign(w,I,U,R){if(this[F]!==0)throw new Error("Client-only method called with server role");typeof U=="function"?(R=U,U=void 0):(typeof U!="object"||U===null)&&(U=void 0);let re=0;if(w=Ai(w),w instanceof Error)throw new Error("Invalid public key argument");if(w.type==="ssh-rsa"&&U)switch(U.hash){case"sha256":re=2;break;case"sha512":re=4;break}w=w.getPublicSSH();let G=13,Y=w.length,te=I.length,ce=0,D=Buffer.allocUnsafe(9+Y+4+te+4);return Xt(D,D.length-4,ce),D[ce+=4]=G,Xt(D,Y,++ce),w.copy(D,ce+=4),Xt(D,te,ce+=Y),I.copy(D,ce+=4),Xt(D,re,ce+=te),typeof R!="function"&&(R=Yo),this[L].push({type:G,cb:R}),this.push(D)}getIdentities(w){if(this[F]!==0)throw new Error("Client-only method called with server role");let I=11,U=0,R=Buffer.allocUnsafe(5);return Xt(R,R.length-4,U),R[U+=4]=I,typeof w!="function"&&(w=Yo),this[L].push({type:I,cb:w}),this.push(R)}failureReply(w){if(this[F]!==1)throw new Error("Server-only method called with client role");if(!(w instanceof g))throw new Error("Wrong request argument");if(w.hasResponded())return!0;let I=0,U=Buffer.allocUnsafe(5);return Xt(U,U.length-4,I),U[I+=4]=5,y(this,w,U)}getIdentitiesReply(w,I){if(this[F]!==1)throw new Error("Server-only method called with client role");if(!(w instanceof g))throw new Error("Wrong request argument");if(w.hasResponded())return!0;if(w.getType()!==11)throw new Error("Invalid response to request");if(!Array.isArray(I))throw new Error("Keys argument must be an array");let U=4,R=[];for(let Y=0;Y<I.length;++Y){let te=I[Y];if(typeof te!="object"||te===null)throw new Error(`Invalid key entry: ${te}`);let ce,D;if(cf(te))ce=te;else if(cf(te.pubKey))ce=te.pubKey;else if(typeof te.pubKey!="object"||te.pubKey===null||({pubKey:ce,comment:D}=te.pubKey,ce=Ai(ce),ce instanceof Error))continue;D=ce.comment||D,ce=ce.getPublicSSH(),U+=4+ce.length,D&&typeof D=="string"?D=Buffer.from(D):Buffer.isBuffer(D)||(D=Pp),U+=4+D.length,R.push({pubKey:ce,comment:D})}let re=0,G=Buffer.allocUnsafe(5+U);Xt(G,G.length-4,re),G[re+=4]=12,Xt(G,R.length,++re),re+=4;for(let Y=0;Y<R.length;++Y){let{pubKey:te,comment:ce}=R[Y];Xt(G,te.length,re),te.copy(G,re+=4),Xt(G,ce.length,re+=te.length),re+=4,ce.length&&(ce.copy(G,re),re+=ce.length)}return y(this,w,G)}signReply(w,I){if(this[F]!==1)throw new Error("Server-only method called with client role");if(!(w instanceof g))throw new Error("Wrong request argument");if(w.hasResponded())return!0;if(w.getType()!==13)throw new Error("Invalid response to request");if(!Buffer.isBuffer(I))throw new Error("Signature argument must be a Buffer");if(I.length===0)throw new Error("Signature argument must be non-empty");let U=0,R=w.getContext(),re=Buffer.byteLength(R),G=Buffer.allocUnsafe(13+re+4+I.length);return Xt(G,G.length-4,U),G[U+=4]=14,Xt(G,4+re+4+I.length,++U),Xt(G,re,U+=4),G.utf8Write(R,U+=4,re),Xt(G,I.length,U+=re),I.copy(G,U+=4),y(this,w,G)}}})(),Go=Symbol("Agent"),gn=Symbol("Agent Keys"),Ln=Symbol("Agent Keys Index"),Rr=Symbol("Agent Init Callbacks"),jo=class{constructor(t){if(typeof t=="string")t=pf(t);else if(!gf(t))throw new Error("Invalid agent argument");this[Go]=t,this[gn]=null,this[Ln]=-1,this[Rr]=null}init(t){if(typeof t!="function"&&(t=Yo),this[gn]===null)if(this[Rr]===null){this[Rr]=[t];let e=(...r)=>{process.nextTick(()=>{let s=this[Rr];this[Rr]=null;for(let i of s)i(...r)})};this[Go].getIdentities(Ei((r,s)=>{if(r)return e(r);if(!Array.isArray(s))return e(new Error("Agent implementation failed to provide keys"));let i=[];for(let o of s)o=Ai(o),!(o instanceof Error)&&i.push(o);this[gn]=i,this[Ln]=-1,e()}))}else this[Rr].push(t);else process.nextTick(t)}nextKey(){return this[gn]===null||++this[Ln]>=this[gn].length?!1:this[gn][this[Ln]]}currentKey(){return this[gn]===null||this[Ln]>=this[gn].length?null:this[gn][this[Ln]]}pos(){return this[gn]===null||this[Ln]>=this[gn].length?-1:this[Ln]}reset(){this[Ln]=-1}sign(...t){this[Go].sign(...t)}};function gf(n){return n instanceof _i}mf.exports={AgentContext:jo,AgentProtocol:zo,BaseAgent:_i,createAgent:pf,CygwinAgent:hf,isAgent:gf,OpenSSHAgent:Nr,PageantAgent:df}});var ia=at((EE,Af)=>{"use strict";var{kMaxLength:Lp}=require("buffer"),{createInflate:Up,constants:{DEFLATE:Dp,INFLATE:Op,Z_DEFAULT_CHUNK:Mp,Z_DEFAULT_COMPRESSION:$p,Z_DEFAULT_MEMLEVEL:Fp,Z_DEFAULT_STRATEGY:Hp,Z_DEFAULT_WINDOWBITS:Qp,Z_PARTIAL_FLUSH:Wp}}=require("zlib"),qp=Up()._handle.constructor;function Kp(){throw new Error("Should not get here")}function Vp(n,t,e){let r=this._owner,s=new Error(n);s.errno=t,s.code=e,r._err=s}function ra(n){n._handle&&(n._handle.close(),n._handle=null)}var ls=class{constructor(t){let e=Qp,r=$p,s=Fp,i=Hp,o=void 0;this._err=void 0,this._writeState=new Uint32Array(2),this._chunkSize=Mp,this._maxOutputLength=Lp,this._outBuffer=Buffer.allocUnsafe(this._chunkSize),this._outOffset=0,this._handle=new qp(t),this._handle._owner=this,this._handle.onerror=Vp,this._handle.init(e,r,s,i,this._writeState,Kp,o)}writeSync(t,e){let r=this._handle;if(!r)throw new Error("Invalid Zlib instance");let s=t.length,i=this._chunkSize-this._outOffset,o=0,a,c,f,l=0,u=this._writeState,h=this._outBuffer,g=this._outOffset,y=this._chunkSize;for(;;){if(r.writeSync(Wp,t,o,s,h,g,i),this._err)throw this._err;a=u[0],c=u[1];let b=s-c,C=i-a;if(C>0){let L=g===0&&C===h.length?h:h.slice(g,g+C);if(g+=C,f?f.push===void 0?f=[f,L]:f.push(L):f=L,l+=L.byteLength,l>this._maxOutputLength)throw ra(this),new Error(`Output length exceeded maximum of ${this._maxOutputLength}`)}else if(C!==0)throw new Error("have should not go down");if((a===0||g>=y)&&(i=y,g=0,h=Buffer.allocUnsafe(y)),a===0)o+=b,s=c;else break}if(this._outBuffer=h,this._outOffset=g,l===0&&(f=Buffer.alloc(0)),e)return f.totalLen=l,f;if(f.push===void 0)return f;let _=Buffer.allocUnsafe(l);for(let b=0,C=0;b<f.length;++b){let L=f[b];_.set(L,C),C+=L.length}return _}},Zo=class{constructor(t){this.allocStart=0,this.allocStartKEX=0,this._protocol=t,this._zlib=new ls(Dp)}cleanup(){this._zlib&&ra(this._zlib)}alloc(t,e){return Buffer.allocUnsafe(t)}finalize(t,e){if(this._protocol._kexinit===void 0||e){let r=this._zlib.writeSync(t,!0),s=this._protocol._cipher.allocPacket(r.totalLen);if(r.push===void 0)s.set(r,5);else for(let i=0,o=5;i<r.length;++i){let a=r[i];s.set(a,o),o+=a.length}return s}return t}},ea=class{constructor(t){this.allocStart=5,this.allocStartKEX=5,this._protocol=t}cleanup(){}alloc(t,e){return this._protocol._kexinit===void 0||e?this._protocol._cipher.allocPacket(t):Buffer.allocUnsafe(t)}finalize(t,e){return t}},ta=class{constructor(){this._zlib=new ls(Op)}cleanup(){this._zlib&&ra(this._zlib)}read(t){return this._zlib.writeSync(t,!1)}},na=class{cleanup(){}read(t){return t}};Af.exports={PacketReader:na,PacketWriter:ea,ZlibPacketReader:ta,ZlibPacketWriter:Zo}});var xf=at((_E,bf)=>{"use strict";var{bufferSlice:sa,bufferParser:T,doFatalError:dt,sigSSHToASN1:Ef,writeUInt32BE:_f}=dn(),{CHANNEL_OPEN_FAILURE:Gp,COMPAT:Yp,MESSAGE:pt,TERMINAL_MODE:yf}=Pn(),{parseKey:zp}=Kn(),jp=Array.from(Object.entries(yf)).reduce((n,[t,e])=>({...n,[t]:e}),{});bf.exports={[pt.DISCONNECT]:(n,t)=>{T.init(t,1);let e=T.readUInt32BE(),r=T.readString(!0),s=T.readString();if(T.clear(),s===void 0)return dt(n,"Inbound: Malformed DISCONNECT packet");n._debug&&n._debug(`Inbound: Received DISCONNECT (${e}, "${r}")`);let i=n._handlers.DISCONNECT;i&&i(n,e,r)},[pt.IGNORE]:(n,t)=>{n._debug&&n._debug("Inbound: Received IGNORE")},[pt.UNIMPLEMENTED]:(n,t)=>{T.init(t,1);let e=T.readUInt32BE();if(T.clear(),e===void 0)return dt(n,"Inbound: Malformed UNIMPLEMENTED packet");n._debug&&n._debug(`Inbound: Received UNIMPLEMENTED (seqno ${e})`)},[pt.DEBUG]:(n,t)=>{T.init(t,1);let e=T.readBool(),r=T.readString(!0),s=T.readString();if(T.clear(),s===void 0)return dt(n,"Inbound: Malformed DEBUG packet");n._debug&&n._debug("Inbound: Received DEBUG");let i=n._handlers.DEBUG;i&&i(n,e,r)},[pt.SERVICE_REQUEST]:(n,t)=>{T.init(t,1);let e=T.readString(!0);if(T.clear(),e===void 0)return dt(n,"Inbound: Malformed SERVICE_REQUEST packet");n._debug&&n._debug(`Inbound: Received SERVICE_REQUEST (${e})`);let r=n._handlers.SERVICE_REQUEST;r&&r(n,e)},[pt.SERVICE_ACCEPT]:(n,t)=>{T.init(t,1);let e=T.readString(!0);if(T.clear(),e===void 0)return dt(n,"Inbound: Malformed SERVICE_ACCEPT packet");n._debug&&n._debug(`Inbound: Received SERVICE_ACCEPT (${e})`);let r=n._handlers.SERVICE_ACCEPT;r&&r(n,e)},[pt.EXT_INFO]:(n,t)=>{T.init(t,1);let e=T.readUInt32BE(),r;if(e!==void 0){r=[];for(let i=0;i<e;++i){let o=T.readString(!0),a=T.readString();if(a!==void 0)if(o==="server-sig-algs"){let c=a.latin1Slice(0,a.length).split(",");r.push({name:o,algs:c});continue}else continue;r=void 0;break}}if(T.clear(),r===void 0)return dt(n,"Inbound: Malformed EXT_INFO packet");n._debug&&n._debug("Inbound: Received EXT_INFO");let s=n._handlers.EXT_INFO;s&&s(n,r)},[pt.USERAUTH_REQUEST]:(n,t)=>{T.init(t,1);let e=T.readString(!0),r=T.readString(!0),s=T.readString(!0),i,o;switch(s){case"none":i=null;break;case"password":{let c=T.readBool();if(c!==void 0&&(i=T.readString(!0),i!==void 0&&c)){let f=T.readString(!0);f!==void 0?i={oldPassword:i,newPassword:f}:i=void 0}break}case"publickey":{let c=T.readBool();if(c!==void 0){let f=T.readString(!0),l=f,u=T.readString(),h;switch(f){case"rsa-sha2-256":l="ssh-rsa",h="sha256";break;case"rsa-sha2-512":l="ssh-rsa",h="sha512";break}if(c){let g=T.pos(),y=T.readString();if(y!==void 0&&(y.length>4+f.length+4&&y.utf8Slice(4,4+f.length)===f&&(y=sa(y,4+f.length+4)),y=Ef(y,l),y)){let _=n._kex.sessionID,b=Buffer.allocUnsafe(4+_.length+g);_f(b,_.length,0),b.set(_,4),b.set(new Uint8Array(t.buffer,t.byteOffset,g),4+_.length),i={keyAlgo:l,key:u,signature:y,blob:b,hashAlgo:h}}}else i={keyAlgo:l,key:u,hashAlgo:h},o="publickey -- check"}break}case"hostbased":{let c=T.readString(!0),f=c,l=T.readString(),u=T.readString(!0),h=T.readString(!0),g;switch(c){case"rsa-sha2-256":f="ssh-rsa",g="sha256";break;case"rsa-sha2-512":f="ssh-rsa",g="sha512";break}let y=T.pos(),_=T.readString();if(_!==void 0&&(_.length>4+c.length+4&&_.utf8Slice(4,4+c.length)===c&&(_=sa(_,4+c.length+4)),_=Ef(_,f),_!==void 0)){let b=n._kex.sessionID,C=Buffer.allocUnsafe(4+b.length+y);_f(C,b.length,0),C.set(b,4),C.set(new Uint8Array(t.buffer,t.byteOffset,y),4+b.length),i={keyAlgo:f,key:l,signature:_,blob:C,localHostname:u,localUsername:h,hashAlgo:g}}break}case"keyboard-interactive":T.skipString(),i=T.readList();break;default:s!==void 0&&(i=T.readRaw())}if(T.clear(),i===void 0)return dt(n,"Inbound: Malformed USERAUTH_REQUEST packet");o===void 0&&(o=s),n._authsQueue.push(s),n._debug&&n._debug(`Inbound: Received USERAUTH_REQUEST (${o})`);let a=n._handlers.USERAUTH_REQUEST;a&&a(n,e,r,s,i)},[pt.USERAUTH_FAILURE]:(n,t)=>{T.init(t,1);let e=T.readList(),r=T.readBool();if(T.clear(),r===void 0)return dt(n,"Inbound: Malformed USERAUTH_FAILURE packet");n._debug&&n._debug(`Inbound: Received USERAUTH_FAILURE (${e})`),n._authsQueue.shift();let s=n._handlers.USERAUTH_FAILURE;s&&s(n,e,r)},[pt.USERAUTH_SUCCESS]:(n,t)=>{n._debug&&n._debug("Inbound: Received USERAUTH_SUCCESS"),n._authsQueue.shift();let e=n._handlers.USERAUTH_SUCCESS;e&&e(n)},[pt.USERAUTH_BANNER]:(n,t)=>{T.init(t,1);let e=T.readString(!0),r=T.readString();if(T.clear(),r===void 0)return dt(n,"Inbound: Malformed USERAUTH_BANNER packet");n._debug&&n._debug("Inbound: Received USERAUTH_BANNER");let s=n._handlers.USERAUTH_BANNER;s&&s(n,e)},60:(n,t)=>{if(!n._authsQueue.length){n._debug&&n._debug("Inbound: Received payload type 60 without auth");return}switch(n._authsQueue[0]){case"password":{T.init(t,1);let e=T.readString(!0),r=T.readString();if(T.clear(),r===void 0)return dt(n,"Inbound: Malformed USERAUTH_PASSWD_CHANGEREQ packet");n._debug&&n._debug("Inbound: Received USERAUTH_PASSWD_CHANGEREQ");let s=n._handlers.USERAUTH_PASSWD_CHANGEREQ;s&&s(n,e);break}case"publickey":{T.init(t,1);let e=T.readString(!0),r=T.readString();if(T.clear(),r===void 0)return dt(n,"Inbound: Malformed USERAUTH_PK_OK packet");n._debug&&n._debug("Inbound: Received USERAUTH_PK_OK"),n._authsQueue.shift();let s=n._handlers.USERAUTH_PK_OK;s&&s(n,e,r);break}case"keyboard-interactive":{T.init(t,1);let e=T.readString(!0),r=T.readString(!0);T.readString();let s=T.readUInt32BE(),i;if(s!==void 0){i=new Array(s);let a;for(a=0;a<s;++a){let c=T.readString(!0),f=T.readBool();if(f===void 0)break;i[a]={prompt:c,echo:f}}a!==s&&(i=void 0)}if(T.clear(),i===void 0)return dt(n,"Inbound: Malformed USERAUTH_INFO_REQUEST packet");n._debug&&n._debug("Inbound: Received USERAUTH_INFO_REQUEST");let o=n._handlers.USERAUTH_INFO_REQUEST;o&&o(n,e,r,i);break}default:n._debug&&n._debug("Inbound: Received unexpected payload type 60")}},61:(n,t)=>{if(!n._authsQueue.length){n._debug&&n._debug("Inbound: Received payload type 61 without auth");return}if(n._authsQueue[0]!=="keyboard-interactive")return dt(n,"Inbound: Received unexpected payload type 61");T.init(t,1);let e=T.readUInt32BE(),r;if(e!==void 0){r=new Array(e);let i;for(i=0;i<e;++i){let o=T.readString(!0);if(o===void 0)break;r[i]=o}i!==e&&(r=void 0)}if(T.clear(),r===void 0)return dt(n,"Inbound: Malformed USERAUTH_INFO_RESPONSE packet");n._debug&&n._debug("Inbound: Received USERAUTH_INFO_RESPONSE");let s=n._handlers.USERAUTH_INFO_RESPONSE;s&&s(n,r)},[pt.GLOBAL_REQUEST]:(n,t)=>{T.init(t,1);let e=T.readString(!0),r=T.readBool(),s;if(r!==void 0)switch(e){case"tcpip-forward":case"cancel-tcpip-forward":{let o=T.readString(!0),a=T.readUInt32BE();a!==void 0&&(s={bindAddr:o,bindPort:a});break}case"streamlocal-forward@openssh.com":case"cancel-streamlocal-forward@openssh.com":{let o=T.readString(!0);o!==void 0&&(s={socketPath:o});break}case"no-more-sessions@openssh.com":s=null;break;case"hostkeys-00@openssh.com":{for(s=[];T.avail()>0;){let o=T.readString();if(o===void 0){s=void 0;break}let a=zp(o);a instanceof Error||s.push(a)}break}default:s=T.readRaw()}if(T.clear(),s===void 0)return dt(n,"Inbound: Malformed GLOBAL_REQUEST packet");n._debug&&n._debug(`Inbound: GLOBAL_REQUEST (${e})`);let i=n._handlers.GLOBAL_REQUEST;i?i(n,e,r,s):n.requestFailure()},[pt.REQUEST_SUCCESS]:(n,t)=>{let e=t.length>1?sa(t,1):null;n._debug&&n._debug("Inbound: REQUEST_SUCCESS");let r=n._handlers.REQUEST_SUCCESS;r&&r(n,e)},[pt.REQUEST_FAILURE]:(n,t)=>{n._debug&&n._debug("Inbound: Received REQUEST_FAILURE");let e=n._handlers.REQUEST_FAILURE;e&&e(n)},[pt.CHANNEL_OPEN]:(n,t)=>{T.init(t,1);let e=T.readString(!0),r=T.readUInt32BE(),s=T.readUInt32BE(),i=T.readUInt32BE(),o;switch(e){case"forwarded-tcpip":case"direct-tcpip":{let c=T.readString(!0),f=T.readUInt32BE(),l=T.readString(!0),u=T.readUInt32BE();u!==void 0&&(o={type:e,sender:r,window:s,packetSize:i,data:{destIP:c,destPort:f,srcIP:l,srcPort:u}});break}case"forwarded-streamlocal@openssh.com":case"direct-streamlocal@openssh.com":{let c=T.readString(!0);c!==void 0&&(o={type:e,sender:r,window:s,packetSize:i,data:{socketPath:c}});break}case"x11":{let c=T.readString(!0),f=T.readUInt32BE();f!==void 0&&(o={type:e,sender:r,window:s,packetSize:i,data:{srcIP:c,srcPort:f}});break}default:o={type:e,sender:r,window:s,packetSize:i,data:{}}}if(T.clear(),o===void 0)return dt(n,"Inbound: Malformed CHANNEL_OPEN packet");n._debug&&n._debug(`Inbound: CHANNEL_OPEN (s:${r}, ${e})`);let a=n._handlers.CHANNEL_OPEN;a?a(n,o):n.channelOpenFail(o.sender,Gp.ADMINISTRATIVELY_PROHIBITED,"","")},[pt.CHANNEL_OPEN_CONFIRMATION]:(n,t)=>{T.init(t,1);let e=T.readUInt32BE(),r=T.readUInt32BE(),s=T.readUInt32BE(),i=T.readUInt32BE(),o=T.avail()?T.readRaw():void 0;if(T.clear(),i===void 0)return dt(n,"Inbound: Malformed CHANNEL_OPEN_CONFIRMATION packet");n._debug&&n._debug(`Inbound: CHANNEL_OPEN_CONFIRMATION (r:${e}, s:${r})`);let a=n._handlers.CHANNEL_OPEN_CONFIRMATION;a&&a(n,{recipient:e,sender:r,window:s,packetSize:i,data:o})},[pt.CHANNEL_OPEN_FAILURE]:(n,t)=>{T.init(t,1);let e=T.readUInt32BE(),r=T.readUInt32BE(),s=T.readString(!0),i=T.readString();if(T.clear(),i===void 0)return dt(n,"Inbound: Malformed CHANNEL_OPEN_FAILURE packet");n._debug&&n._debug(`Inbound: CHANNEL_OPEN_FAILURE (r:${e})`);let o=n._handlers.CHANNEL_OPEN_FAILURE;o&&o(n,e,r,s)},[pt.CHANNEL_WINDOW_ADJUST]:(n,t)=>{T.init(t,1);let e=T.readUInt32BE(),r=T.readUInt32BE();if(T.clear(),r===void 0)return dt(n,"Inbound: Malformed CHANNEL_WINDOW_ADJUST packet");n._debug&&n._debug(`Inbound: CHANNEL_WINDOW_ADJUST (r:${e}, ${r})`);let s=n._handlers.CHANNEL_WINDOW_ADJUST;s&&s(n,e,r)},[pt.CHANNEL_DATA]:(n,t)=>{T.init(t,1);let e=T.readUInt32BE(),r=T.readString();if(T.clear(),r===void 0)return dt(n,"Inbound: Malformed CHANNEL_DATA packet");n._debug&&n._debug(`Inbound: CHANNEL_DATA (r:${e}, ${r.length})`);let s=n._handlers.CHANNEL_DATA;s&&s(n,e,r)},[pt.CHANNEL_EXTENDED_DATA]:(n,t)=>{T.init(t,1);let e=T.readUInt32BE(),r=T.readUInt32BE(),s=T.readString();if(T.clear(),s===void 0)return dt(n,"Inbound: Malformed CHANNEL_EXTENDED_DATA packet");n._debug&&n._debug(`Inbound: CHANNEL_EXTENDED_DATA (r:${e}, ${s.length})`);let i=n._handlers.CHANNEL_EXTENDED_DATA;i&&i(n,e,s,r)},[pt.CHANNEL_EOF]:(n,t)=>{T.init(t,1);let e=T.readUInt32BE();if(T.clear(),e===void 0)return dt(n,"Inbound: Malformed CHANNEL_EOF packet");n._debug&&n._debug(`Inbound: CHANNEL_EOF (r:${e})`);let r=n._handlers.CHANNEL_EOF;r&&r(n,e)},[pt.CHANNEL_CLOSE]:(n,t)=>{T.init(t,1);let e=T.readUInt32BE();if(T.clear(),e===void 0)return dt(n,"Inbound: Malformed CHANNEL_CLOSE packet");n._debug&&n._debug(`Inbound: CHANNEL_CLOSE (r:${e})`);let r=n._handlers.CHANNEL_CLOSE;r&&r(n,e)},[pt.CHANNEL_REQUEST]:(n,t)=>{T.init(t,1);let e=T.readUInt32BE(),r=T.readString(!0),s=T.readBool(),i;if(s!==void 0)switch(r){case"exit-status":i=T.readUInt32BE(),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${i})`);break;case"exit-signal":{let a,c;if(n._compatFlags&Yp.OLD_EXIT){let l=T.readUInt32BE();switch(l){case 1:a="HUP";break;case 2:a="INT";break;case 3:a="QUIT";break;case 6:a="ABRT";break;case 9:a="KILL";break;case 14:a="ALRM";break;case 15:a="TERM";break;default:l!==void 0&&(a=`UNKNOWN (${l})`)}c=!1}else a=T.readString(!0),c=T.readBool(),c===void 0&&(a=void 0);let f=T.readString(!0);T.skipString()!==void 0&&(i={signal:a,coreDumped:c,errorMessage:f}),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${a})`);break}case"pty-req":{let a=T.readString(!0),c=T.readUInt32BE(),f=T.readUInt32BE(),l=T.readUInt32BE(),u=T.readUInt32BE(),h=T.readString();if(h!==void 0){T.init(h,1);let g={};for(;T.avail();){let y=T.readByte();if(y===yf.TTY_OP_END)break;let _=jp[y],b=T.readUInt32BE();if(y===void 0||_===void 0||b===void 0){g=void 0;break}g[_]=b}g!==void 0&&(i={term:a,cols:c,rows:f,width:l,height:u,modes:g})}n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break}case"window-change":{let a=T.readUInt32BE(),c=T.readUInt32BE(),f=T.readUInt32BE(),l=T.readUInt32BE();l!==void 0&&(i={cols:a,rows:c,width:f,height:l}),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break}case"x11-req":{let a=T.readBool(),c=T.readString(!0),f=T.readString(),l=T.readUInt32BE();l!==void 0&&(i={single:a,protocol:c,cookie:f,screen:l}),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break}case"env":{let a=T.readString(!0),c=T.readString(!0);c!==void 0&&(i={name:a,value:c}),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${a}=${c})`);break}case"shell":i=null,n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break;case"exec":i=T.readString(!0),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${i})`);break;case"subsystem":i=T.readString(!0),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${i})`);break;case"signal":i=T.readString(!0),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${i})`);break;case"xon-xoff":i=T.readBool(),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${i})`);break;case"auth-agent-req@openssh.com":i=null,n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break;default:i=T.avail()?T.readRaw():null,n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`)}if(T.clear(),i===void 0)return dt(n,"Inbound: Malformed CHANNEL_REQUEST packet");let o=n._handlers.CHANNEL_REQUEST;o&&o(n,e,r,s,i)},[pt.CHANNEL_SUCCESS]:(n,t)=>{T.init(t,1);let e=T.readUInt32BE();if(T.clear(),e===void 0)return dt(n,"Inbound: Malformed CHANNEL_SUCCESS packet");n._debug&&n._debug(`Inbound: CHANNEL_SUCCESS (r:${e})`);let r=n._handlers.CHANNEL_SUCCESS;r&&r(n,e)},[pt.CHANNEL_FAILURE]:(n,t)=>{T.init(t,1);let e=T.readUInt32BE();if(T.clear(),e===void 0)return dt(n,"Inbound: Malformed CHANNEL_FAILURE packet");n._debug&&n._debug(`Inbound: CHANNEL_FAILURE (r:${e})`);let r=n._handlers.CHANNEL_FAILURE;r&&r(n,e)}}});var us=at((yE,Sf)=>{"use strict";var oa=new Array(256);[ds().HANDLERS,xf()].forEach(n=>{for(let[t,e]of Object.entries(n))t=+t,isFinite(t)&&t>=0&&t<oa.length&&(oa[t]=e)});Sf.exports=oa});var ds=at((xE,Tf)=>{"use strict";var{createDiffieHellman:Xp,createDiffieHellmanGroup:Jp,createECDH:Zp,createHash:ca,createPublicKey:eg,diffieHellman:tg,generateKeyPairSync:ng,randomFillSync:rg}=require("crypto"),{Ber:wf}=ni(),{COMPAT:fa,curve25519Supported:ig,DEFAULT_KEX:If,DEFAULT_SERVER_HOST_KEY:Cf,DEFAULT_CIPHER:hs,DEFAULT_MAC:ps,DEFAULT_COMPRESSION:gs,DISCONNECT_REASON:Ge,MESSAGE:lt}=Pn(),{CIPHER_INFO:Lr,createCipher:sg,createDecipher:og,MAC_INFO:vf}=Qn(),{parseDERKey:ag}=Kn(),{bufferFill:cg,bufferParser:Ve,convertSignature:fg,doFatalError:Ye,FastBuffer:lg,sigSSHToASN1:ug,writeUInt32BE:Ot}=dn(),{PacketReader:kf,PacketWriter:Bf,ZlibPacketReader:ms,ZlibPacketWriter:As}=ia(),Pr,dg=2048,hg=8192,pg=Buffer.alloc(0);function Rf(n){let t;if(n._compatFlags&fa.BAD_DHGEX){let e=n._offer.lists.kex,r=e.array,s=!1;for(let i=0;i<r.length;++i)r[i].includes("group-exchange")&&(s||(s=!0,r=r.slice()),r.splice(i--,1));if(s){let i=17+n._offer.totalSize+1+4,o=Buffer.from(r.join(","));i-=e.buffer.length-o.length;let a=n._offer.lists.all,c=new Uint8Array(a.buffer,a.byteOffset+4+e.buffer.length,a.length-(4+e.buffer.length));t=Buffer.allocUnsafe(i),Ot(t,o.length,17),t.set(o,21),t.set(c,21+o.length)}}t===void 0&&(t=Buffer.allocUnsafe(17+n._offer.totalSize+1+4),n._offer.copyAllTo(t,17)),n._debug&&n._debug("Outbound: Sending KEXINIT"),t[0]=lt.KEXINIT,rg(t,1,16),cg(t,0,t.length-5),n._kexinit=t,n._packetRW.write.allocStart=0;{let e=n._packetRW.write.allocStartKEX,r=n._packetRW.write.alloc(t.length,!0);r.set(t,e),n._cipher.encrypt(n._packetRW.write.finalize(r,!0))}}function Nf(n,t){let e={kex:void 0,serverHostKey:void 0,cs:{cipher:void 0,mac:void 0,compress:void 0,lang:void 0},sc:{cipher:void 0,mac:void 0,compress:void 0,lang:void 0}};if(Ve.init(t,17),(e.kex=Ve.readList())===void 0||(e.serverHostKey=Ve.readList())===void 0||(e.cs.cipher=Ve.readList())===void 0||(e.sc.cipher=Ve.readList())===void 0||(e.cs.mac=Ve.readList())===void 0||(e.sc.mac=Ve.readList())===void 0||(e.cs.compress=Ve.readList())===void 0||(e.sc.compress=Ve.readList())===void 0||(e.cs.lang=Ve.readList())===void 0||(e.sc.lang=Ve.readList())===void 0)return Ve.clear(),Ye(n,"Received malformed KEXINIT","handshake",Ge.KEY_EXCHANGE_FAILED);let r=Ve.pos(),s=r<t.length&&t[r]===1;Ve.clear();let i=n._offer,o=e,a=i.lists.kex.array;if(n._compatFlags&fa.BAD_DHGEX){let k=!1;for(let K=0;K<a.length;++K)a[K].indexOf("group-exchange")!==-1&&(k||(k=!0,a=a.slice()),a.splice(K--,1))}let c,f,l,u=n._debug;u&&u("Inbound: Handshake in progress"),u&&u(`Handshake: (local) KEX method: ${a}`),u&&u(`Handshake: (remote) KEX method: ${o.kex}`);let h;if(n._server?(f=a,c=o.kex,h=c.indexOf("ext-info-c")!==-1):(f=o.kex,c=a,h=f.indexOf("ext-info-s")!==-1),n._strictMode===void 0&&(n._server?n._strictMode=c.indexOf("kex-strict-c-v00@openssh.com")!==-1:n._strictMode=f.indexOf("kex-strict-s-v00@openssh.com")!==-1,n._strictMode&&(u&&u("Handshake: strict KEX mode enabled"),n._decipher.inSeqno!==1)))return u&&u("Handshake: KEXINIT not first packet in strict KEX mode"),Ye(n,"Handshake failed: KEXINIT not first packet in strict KEX mode","handshake",Ge.KEY_EXCHANGE_FAILED);for(l=0;l<c.length&&f.indexOf(c[l])===-1;++l);if(l===c.length)return u&&u("Handshake: no matching key exchange algorithm"),Ye(n,"Handshake failed: no matching key exchange algorithm","handshake",Ge.KEY_EXCHANGE_FAILED);e.kex=c[l],u&&u(`Handshake: KEX algorithm: ${c[l]}`),s&&(!o.kex.length||c[l]!==o.kex[0])&&(n._skipNextInboundPacket=!0);let g=i.lists.serverHostKey.array;for(u&&u(`Handshake: (local) Host key format: ${g}`),u&&u(`Handshake: (remote) Host key format: ${o.serverHostKey}`),n._server?(f=g,c=o.serverHostKey):(f=o.serverHostKey,c=g),l=0;l<c.length&&f.indexOf(c[l])===-1;++l);if(l===c.length)return u&&u("Handshake: No matching host key format"),Ye(n,"Handshake failed: no matching host key format","handshake",Ge.KEY_EXCHANGE_FAILED);e.serverHostKey=c[l],u&&u(`Handshake: Host key format: ${c[l]}`);let y=i.lists.cs.cipher.array;for(u&&u(`Handshake: (local) C->S cipher: ${y}`),u&&u(`Handshake: (remote) C->S cipher: ${o.cs.cipher}`),n._server?(f=y,c=o.cs.cipher):(f=o.cs.cipher,c=y),l=0;l<c.length&&f.indexOf(c[l])===-1;++l);if(l===c.length)return u&&u("Handshake: No matching C->S cipher"),Ye(n,"Handshake failed: no matching C->S cipher","handshake",Ge.KEY_EXCHANGE_FAILED);e.cs.cipher=c[l],u&&u(`Handshake: C->S Cipher: ${c[l]}`);let _=i.lists.sc.cipher.array;for(u&&u(`Handshake: (local) S->C cipher: ${_}`),u&&u(`Handshake: (remote) S->C cipher: ${o.sc.cipher}`),n._server?(f=_,c=o.sc.cipher):(f=o.sc.cipher,c=_),l=0;l<c.length&&f.indexOf(c[l])===-1;++l);if(l===c.length)return u&&u("Handshake: No matching S->C cipher"),Ye(n,"Handshake failed: no matching S->C cipher","handshake",Ge.KEY_EXCHANGE_FAILED);e.sc.cipher=c[l],u&&u(`Handshake: S->C cipher: ${c[l]}`);let b=i.lists.cs.mac.array;if(u&&u(`Handshake: (local) C->S MAC: ${b}`),u&&u(`Handshake: (remote) C->S MAC: ${o.cs.mac}`),Lr[e.cs.cipher].authLen>0)e.cs.mac="",u&&u("Handshake: C->S MAC: <implicit>");else{for(n._server?(f=b,c=o.cs.mac):(f=o.cs.mac,c=b),l=0;l<c.length&&f.indexOf(c[l])===-1;++l);if(l===c.length)return u&&u("Handshake: No matching C->S MAC"),Ye(n,"Handshake failed: no matching C->S MAC","handshake",Ge.KEY_EXCHANGE_FAILED);e.cs.mac=c[l],u&&u(`Handshake: C->S MAC: ${c[l]}`)}let C=i.lists.sc.mac.array;if(u&&u(`Handshake: (local) S->C MAC: ${C}`),u&&u(`Handshake: (remote) S->C MAC: ${o.sc.mac}`),Lr[e.sc.cipher].authLen>0)e.sc.mac="",u&&u("Handshake: S->C MAC: <implicit>");else{for(n._server?(f=C,c=o.sc.mac):(f=o.sc.mac,c=C),l=0;l<c.length&&f.indexOf(c[l])===-1;++l);if(l===c.length)return u&&u("Handshake: No matching S->C MAC"),Ye(n,"Handshake failed: no matching S->C MAC","handshake",Ge.KEY_EXCHANGE_FAILED);e.sc.mac=c[l],u&&u(`Handshake: S->C MAC: ${c[l]}`)}let L=i.lists.cs.compress.array;for(u&&u(`Handshake: (local) C->S compression: ${L}`),u&&u(`Handshake: (remote) C->S compression: ${o.cs.compress}`),n._server?(f=L,c=o.cs.compress):(f=o.cs.compress,c=L),l=0;l<c.length&&f.indexOf(c[l])===-1;++l);if(l===c.length)return u&&u("Handshake: No matching C->S compression"),Ye(n,"Handshake failed: no matching C->S compression","handshake",Ge.KEY_EXCHANGE_FAILED);e.cs.compress=c[l],u&&u(`Handshake: C->S compression: ${c[l]}`);let F=i.lists.sc.compress.array;for(u&&u(`Handshake: (local) S->C compression: ${F}`),u&&u(`Handshake: (remote) S->C compression: ${o.sc.compress}`),n._server?(f=F,c=o.sc.compress):(f=o.sc.compress,c=F),l=0;l<c.length&&f.indexOf(c[l])===-1;++l);if(l===c.length)return u&&u("Handshake: No matching S->C compression"),Ye(n,"Handshake failed: no matching S->C compression","handshake",Ge.KEY_EXCHANGE_FAILED);e.sc.compress=c[l],u&&u(`Handshake: S->C compression: ${c[l]}`),e.cs.lang="",e.sc.lang="",n._kex&&(n._kexinit||Rf(n),n._decipher._onPayload=Pf.bind(n,{firstPacket:!1})),n._kex=gg(e,n,t),n._kex.remoteExtInfoEnabled=h,n._kex.start()}var gg=(()=>{function n(o){let a=0,c=o.length;for(;o[a]===0;)++a,--c;let f;return o[a]&128?(f=Buffer.allocUnsafe(1+c),f[0]=0,o.copy(f,1,a),o=f):c!==o.length&&(f=Buffer.allocUnsafe(c),o.copy(f,0,a),o=f),o}class t{constructor(a,c,f){this._protocol=c,this.sessionID=c._kex?c._kex.sessionID:void 0,this.negotiated=a,this.remoteExtInfoEnabled=!1,this._step=1,this._public=null,this._dh=null,this._sentNEWKEYS=!1,this._receivedNEWKEYS=!1,this._finished=!1,this._hostVerified=!1,this._kexinit=c._kexinit,this._remoteKexinit=f,this._identRaw=c._identRaw,this._remoteIdentRaw=c._remoteIdentRaw,this._hostKey=void 0,this._dhData=void 0,this._sig=void 0}finish(a){if(this._finished)return!1;this._finished=!0;let c=this._protocol._server,f=this.negotiated,l=this.convertPublicKey(this._dhData),u=this.computeSecret(this._dhData);if(u instanceof Error)return u.message=`Error while computing DH secret (${this.type}): ${u.message}`,u.level="handshake",Ye(this._protocol,u,Ge.KEY_EXCHANGE_FAILED);let h=ca(this.hashName);yn(h,c?this._remoteIdentRaw:this._identRaw),yn(h,c?this._identRaw:this._remoteIdentRaw),yn(h,c?this._remoteKexinit:this._kexinit),yn(h,c?this._kexinit:this._remoteKexinit);let g=c?this._hostKey.getPublicSSH():this._hostKey;if(yn(h,g),this.type==="groupex"){let F=this.getDHParams(),k=Buffer.allocUnsafe(4);Ot(k,this._minBits,0),h.update(k),Ot(k,this._prefBits,0),h.update(k),Ot(k,this._maxBits,0),h.update(k),yn(h,F.prime),yn(h,F.generator)}yn(h,c?l:this.getPublicKey());let y=c?this.getPublicKey():l;yn(h,y),yn(h,u);let _=h.digest();if(c){let F;switch(this.negotiated.serverHostKey){case"rsa-sha2-256":F="sha256";break;case"rsa-sha2-512":F="sha512";break}this._protocol._debug&&this._protocol._debug("Generating signature ...");let k=this._hostKey.sign(_,F);if(k instanceof Error)return Ye(this._protocol,`Handshake failed: signature generation failed for ${this._hostKey.type} host key: ${k.message}`,"handshake",Ge.KEY_EXCHANGE_FAILED);if(k=fg(k,this._hostKey.type),k===!1)return Ye(this._protocol,`Handshake failed: signature conversion failed for ${this._hostKey.type} host key`,"handshake",Ge.KEY_EXCHANGE_FAILED);let K=this.negotiated.serverHostKey,ee=Buffer.byteLength(K),O=4+ee+4+k.length,x=this._protocol._packetRW.write.allocStartKEX,w=this._protocol._packetRW.write.alloc(5+g.length+4+y.length+4+O,!0);if(w[x]=lt.KEXDH_REPLY,Ot(w,g.length,++x),w.set(g,x+=4),Ot(w,y.length,x+=g.length),w.set(y,x+=4),Ot(w,O,x+=y.length),Ot(w,ee,x+=4),w.utf8Write(K,x+=4,ee),Ot(w,k.length,x+=ee),w.set(k,x+=4),this._protocol._debug){let I;switch(this.type){case"group":I="KEXDH_REPLY";break;case"groupex":I="KEXDH_GEX_REPLY";break;default:I="KEXECDH_REPLY"}this._protocol._debug(`Outbound: Sending ${I}`)}this._protocol._cipher.encrypt(this._protocol._packetRW.write.finalize(w,!0))}else{Ve.init(this._sig,0);let F=Ve.readString(!0);if(!F)return Ye(this._protocol,"Malformed packet while reading signature","handshake",Ge.KEY_EXCHANGE_FAILED);if(F!==f.serverHostKey)return Ye(this._protocol,`Wrong signature type: ${F}, expected: ${f.serverHostKey}`,"handshake",Ge.KEY_EXCHANGE_FAILED);let k=Ve.readString();if(Ve.clear(),k===void 0)return Ye(this._protocol,"Malformed packet while reading signature","handshake",Ge.KEY_EXCHANGE_FAILED);if(!(k=ug(k,F)))return Ye(this._protocol,"Malformed signature","handshake",Ge.KEY_EXCHANGE_FAILED);let K;{Ve.init(this._hostKey,0);let x=Ve.readString(!0),w=this._hostKey.slice(Ve.pos());if(Ve.clear(),K=ag(w,x),K instanceof Error)return K.level="handshake",Ye(this._protocol,K,Ge.KEY_EXCHANGE_FAILED)}let ee;switch(this.negotiated.serverHostKey){case"rsa-sha2-256":ee="sha256";break;case"rsa-sha2-512":ee="sha512";break}this._protocol._debug&&this._protocol._debug("Verifying signature ...");let O=K.verify(_,k,ee);if(O!==!0)return O instanceof Error?this._protocol._debug&&this._protocol._debug(`Signature verification failed: ${O.stack}`):this._protocol._debug&&this._protocol._debug("Signature verification failed"),Ye(this._protocol,"Handshake failed: signature verification failed","handshake",Ge.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Verified signature")}(c||!a)&&Es(this);let b,C,L=F=>{if(b)return Es(this),b.outbound.seqno=this._protocol._cipher.outSeqno,this._protocol._cipher.free(),this._protocol._cipher=sg(b),this._protocol._packetRW.write=C,b=void 0,C=void 0,this._protocol._onHandshakeComplete(f),!1;this.sessionID||(this.sessionID=_);{let te=Buffer.allocUnsafe(4+u.length);Ot(te,u.length,0),te.set(u,4),u=te}let k=Lr[f.cs.cipher],K=Lr[f.sc.cipher],ee=Tr(k.ivLen,this.hashName,u,_,this.sessionID,"A"),O=Tr(K.ivLen,this.hashName,u,_,this.sessionID,"B"),x=Tr(k.keyLen,this.hashName,u,_,this.sessionID,"C"),w=Tr(K.keyLen,this.hashName,u,_,this.sessionID,"D"),I,U;k.authLen||(I=vf[f.cs.mac],U=Tr(I.len,this.hashName,u,_,this.sessionID,"E"));let R,re;K.authLen||(R=vf[f.sc.mac],re=Tr(R.len,this.hashName,u,_,this.sessionID,"F"));let G={inbound:{onPayload:this._protocol._onPayload,seqno:this._protocol._decipher.inSeqno,decipherInfo:c?k:K,decipherIV:c?ee:O,decipherKey:c?x:w,macInfo:c?I:R,macKey:c?U:re},outbound:{onWrite:this._protocol._onWrite,seqno:this._protocol._cipher.outSeqno,cipherInfo:c?K:k,cipherIV:c?O:ee,cipherKey:c?w:x,macInfo:c?R:I,macKey:c?re:U}};this._protocol._decipher.free(),b=G,this._protocol._decipher=og(G);let Y={read:void 0,write:void 0};switch(f.cs.compress){case"zlib":c?Y.read=new ms:Y.write=new As(this._protocol);break;case"zlib@openssh.com":if(this._protocol._authenticated){c?Y.read=new ms:Y.write=new As(this._protocol);break}default:c?Y.read=new kf:Y.write=new Bf(this._protocol)}switch(f.sc.compress){case"zlib":c?Y.write=new As(this._protocol):Y.read=new ms;break;case"zlib@openssh.com":if(this._protocol._authenticated){c?Y.write=new As(this._protocol):Y.read=new ms;break}default:c?Y.write=new Bf(this._protocol):Y.read=new kf}return this._protocol._packetRW.read.cleanup(),this._protocol._packetRW.write.cleanup(),this._protocol._packetRW.read=Y.read,C=Y.write,this._public=null,this._dh=null,this._kexinit=this._protocol._kexinit=void 0,this._remoteKexinit=void 0,this._identRaw=void 0,this._remoteIdentRaw=void 0,this._hostKey=void 0,this._dhData=void 0,this._sig=void 0,F?!1:L()};if((c||a)&&(this.finish=L),!c)return L(a)}start(){if(!this._protocol._server){if(this._protocol._debug){let l;this.type==="group"?l="KEXDH_INIT":l="KEXECDH_INIT",this._protocol._debug(`Outbound: Sending ${l}`)}let a=this.getPublicKey(),c=this._protocol._packetRW.write.allocStartKEX,f=this._protocol._packetRW.write.alloc(5+a.length,!0);f[c]=lt.KEXDH_INIT,Ot(f,a.length,++c),f.set(a,c+=4),this._protocol._cipher.encrypt(this._protocol._packetRW.write.finalize(f,!0))}}getPublicKey(){this.generateKeys();let a=this._public;if(a)return this.convertPublicKey(a)}convertPublicKey(a){let c,f=0,l=a.length;for(;a[f]===0;)++f,--l;return a[f]&128?(c=Buffer.allocUnsafe(1+l),c[0]=0,a.copy(c,1,f),c):(l!==a.length&&(c=Buffer.allocUnsafe(l),a.copy(c,0,f),a=c),a)}computeSecret(a){this.generateKeys();try{return n(this._dh.computeSecret(a))}catch(c){return c}}parse(a){let c=a[0];switch(this._step){case 1:if(this._protocol._server){if(c!==lt.KEXDH_INIT)return Ye(this._protocol,`Received packet ${c} instead of ${lt.KEXDH_INIT}`,"handshake",Ge.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH Init"),Ve.init(a,1);let f=Ve.readString();if(Ve.clear(),f===void 0)return Ye(this._protocol,"Received malformed KEX*_INIT","handshake",Ge.KEY_EXCHANGE_FAILED);this._dhData=f;let l=this._protocol._hostKeys[this.negotiated.serverHostKey];Array.isArray(l)&&(l=l[0]),this._hostKey=l,this.finish()}else{if(c!==lt.KEXDH_REPLY)return Ye(this._protocol,`Received packet ${c} instead of ${lt.KEXDH_REPLY}`,"handshake",Ge.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH Reply"),Ve.init(a,1);let f,l,u;if((f=Ve.readString())===void 0||(l=Ve.readString())===void 0||(u=Ve.readString())===void 0)return Ve.clear(),Ye(this._protocol,"Received malformed KEX*_REPLY","handshake",Ge.KEY_EXCHANGE_FAILED);Ve.clear(),Ve.init(f,0);let h=Ve.readString(!0);if(Ve.clear(),h===void 0)return Ye(this._protocol,"Received malformed host public key","handshake",Ge.KEY_EXCHANGE_FAILED);if(h!==this.negotiated.serverHostKey)switch(this.negotiated.serverHostKey){case"rsa-sha2-256":case"rsa-sha2-512":if(h==="ssh-rsa")break;default:return Ye(this._protocol,"Host key does not match negotiated type","handshake",Ge.KEY_EXCHANGE_FAILED)}this._hostKey=f,this._dhData=l,this._sig=u;let g=!1,y;if(this._protocol._hostVerifier===void 0?(y=!0,this._protocol._debug&&this._protocol._debug("Host accepted by default (no verification)")):y=this._protocol._hostVerifier(f,_=>{if(!g){if(g=!0,_===!1)return this._protocol._debug&&this._protocol._debug("Host denied (verification failed)"),Ye(this._protocol,"Host denied (verification failed)","handshake",Ge.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Host accepted (verified)"),this._hostVerified=!0,this._receivedNEWKEYS?this.finish():Es(this)}}),y===void 0){++this._step;return}if(g=!0,y===!1)return this._protocol._debug&&this._protocol._debug("Host denied (verification failed)"),Ye(this._protocol,"Host denied (verification failed)","handshake",Ge.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Host accepted (verified)"),this._hostVerified=!0,Es(this)}++this._step;break;case 2:return c!==lt.NEWKEYS?Ye(this._protocol,`Received packet ${c} instead of ${lt.NEWKEYS}`,"handshake",Ge.KEY_EXCHANGE_FAILED):(this._protocol._debug&&this._protocol._debug("Inbound: NEWKEYS"),this._receivedNEWKEYS=!0,this._protocol._strictMode&&(this._protocol._decipher.inSeqno=0),++this._step,this.finish(!this._protocol._server&&!this._hostVerified));default:return Ye(this._protocol,`Received unexpected packet ${c} after NEWKEYS`,"handshake",Ge.KEY_EXCHANGE_FAILED)}}}class e extends t{constructor(a,...c){super(...c),this.type="25519",this.hashName=a,this._keys=null}generateKeys(){this._keys||(this._keys=ng("x25519"))}getPublicKey(){return this.generateKeys(),this._keys.publicKey.export({type:"spki",format:"der"}).slice(-32)}convertPublicKey(a){let c,f=0,l=a.length;for(;a[f]===0;)++f,--l;return a.length===32||l!==a.length&&(c=Buffer.allocUnsafe(l),a.copy(c,0,f),a=c),a}computeSecret(a){this.generateKeys();try{let c=new wf.Writer;return c.startSequence(),c.startSequence(),c.writeOID("1.3.101.110"),c.endSequence(),c.startSequence(wf.BitString),c.writeByte(0),c._ensure(a.length),a.copy(c._buf,c._offset,0,a.length),c._offset+=a.length,c.endSequence(),c.endSequence(),n(tg({privateKey:this._keys.privateKey,publicKey:eg({key:c.buffer,type:"spki",format:"der"})}))}catch(c){return c}}}class r extends t{constructor(a,c,...f){super(...f),this.type="ecdh",this.curveName=a,this.hashName=c}generateKeys(){this._dh||(this._dh=Zp(this.curveName),this._public=this._dh.generateKeys())}}class s extends t{constructor(a,...c){super(...c),this.type="groupex",this.hashName=a,this._prime=null,this._generator=null,this._minBits=dg,this._prefBits=mg(this.negotiated),this._protocol._compatFlags&fa.BUG_DHGEX_LARGE&&(this._prefBits=Math.min(this._prefBits,4096)),this._maxBits=hg}start(){if(this._protocol._server)return;this._protocol._debug&&this._protocol._debug("Outbound: Sending KEXDH_GEX_REQUEST");let a=this._protocol._packetRW.write.allocStartKEX,c=this._protocol._packetRW.write.alloc(13,!0);c[a]=lt.KEXDH_GEX_REQUEST,Ot(c,this._minBits,++a),Ot(c,this._prefBits,a+=4),Ot(c,this._maxBits,a+=4),this._protocol._cipher.encrypt(this._protocol._packetRW.write.finalize(c,!0))}generateKeys(){!this._dh&&this._prime&&this._generator&&(this._dh=Xp(this._prime,this._generator),this._public=this._dh.generateKeys())}setDHParams(a,c){if(!Buffer.isBuffer(a))throw new Error("Invalid prime value");if(!Buffer.isBuffer(c))throw new Error("Invalid generator value");this._prime=a,this._generator=c}getDHParams(){if(this._dh)return{prime:n(this._dh.getPrime()),generator:n(this._dh.getGenerator())}}parse(a){let c=a[0];switch(this._step){case 1:{if(this._protocol._server)return c!==lt.KEXDH_GEX_REQUEST?Ye(this._protocol,`Received packet ${c} instead of `+lt.KEXDH_GEX_REQUEST,"handshake",Ge.KEY_EXCHANGE_FAILED):Ye(this._protocol,"Group exchange not implemented for server","handshake",Ge.KEY_EXCHANGE_FAILED);if(c!==lt.KEXDH_GEX_GROUP)return Ye(this._protocol,`Received packet ${c} instead of ${lt.KEXDH_GEX_GROUP}`,"handshake",Ge.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH GEX Group"),Ve.init(a,1);let f,l;if((f=Ve.readString())===void 0||(l=Ve.readString())===void 0)return Ve.clear(),Ye(this._protocol,"Received malformed KEXDH_GEX_GROUP","handshake",Ge.KEY_EXCHANGE_FAILED);Ve.clear(),this.setDHParams(f,l),this.generateKeys();let u=this.getPublicKey();this._protocol._debug&&this._protocol._debug("Outbound: Sending KEXDH_GEX_INIT");let h=this._protocol._packetRW.write.allocStartKEX,g=this._protocol._packetRW.write.alloc(5+u.length,!0);g[h]=lt.KEXDH_GEX_INIT,Ot(g,u.length,++h),g.set(u,h+=4),this._protocol._cipher.encrypt(this._protocol._packetRW.write.finalize(g,!0)),++this._step;break}case 2:if(this._protocol._server)return c!==lt.KEXDH_GEX_INIT?Ye(this._protocol,`Received packet ${c} instead of ${lt.KEXDH_GEX_INIT}`,"handshake",Ge.KEY_EXCHANGE_FAILED):(this._protocol._debug&&this._protocol._debug("Received DH GEX Init"),Ye(this._protocol,"Group exchange not implemented for server","handshake",Ge.KEY_EXCHANGE_FAILED));if(c!==lt.KEXDH_GEX_REPLY)return Ye(this._protocol,`Received packet ${c} instead of ${lt.KEXDH_GEX_REPLY}`,"handshake",Ge.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH GEX Reply"),this._step=1,a[0]=lt.KEXDH_REPLY,this.parse=t.prototype.parse,this.parse(a)}}}class i extends t{constructor(a,c,...f){super(...f),this.type="group",this.groupName=a,this.hashName=c}start(){if(!this._protocol._server){this._protocol._debug&&this._protocol._debug("Outbound: Sending KEXDH_INIT");let a=this.getPublicKey(),c=this._protocol._packetRW.write.allocStartKEX,f=this._protocol._packetRW.write.alloc(5+a.length,!0);f[c]=lt.KEXDH_INIT,Ot(f,a.length,++c),f.set(a,c+=4),this._protocol._cipher.encrypt(this._protocol._packetRW.write.finalize(f,!0))}}generateKeys(){this._dh||(this._dh=Jp(this.groupName),this._public=this._dh.generateKeys())}getDHParams(){if(this._dh)return{prime:n(this._dh.getPrime()),generator:n(this._dh.getGenerator())}}}return(o,...a)=>{if(typeof o!="object"||o===null)throw new Error("Invalid negotiated argument");let c=o.kex;if(typeof c=="string"){switch(a=[o,...a],c){case"curve25519-sha256":case"curve25519-sha256@libssh.org":if(!ig)break;return new e("sha256",...a);case"ecdh-sha2-nistp256":return new r("prime256v1","sha256",...a);case"ecdh-sha2-nistp384":return new r("secp384r1","sha384",...a);case"ecdh-sha2-nistp521":return new r("secp521r1","sha512",...a);case"diffie-hellman-group1-sha1":return new i("modp2","sha1",...a);case"diffie-hellman-group14-sha1":return new i("modp14","sha1",...a);case"diffie-hellman-group14-sha256":return new i("modp14","sha256",...a);case"diffie-hellman-group15-sha512":return new i("modp15","sha512",...a);case"diffie-hellman-group16-sha512":return new i("modp16","sha512",...a);case"diffie-hellman-group17-sha512":return new i("modp17","sha512",...a);case"diffie-hellman-group18-sha512":return new i("modp18","sha512",...a);case"diffie-hellman-group-exchange-sha1":return new s("sha1",...a);case"diffie-hellman-group-exchange-sha256":return new s("sha256",...a)}throw new Error(`Unsupported key exchange algorithm: ${c}`)}throw new Error(`Invalid key exchange type: ${c}`)}})(),aa=(()=>{let n=["kex","serverHostKey",["cs","cipher"],["sc","cipher"],["cs","mac"],["sc","mac"],["cs","compress"],["sc","compress"],["cs","lang"],["sc","lang"]];return class{constructor(e){if(typeof e!="object"||e===null)throw new TypeError("Argument must be an object");let r={kex:void 0,serverHostKey:void 0,cs:{cipher:void 0,mac:void 0,compress:void 0,lang:void 0},sc:{cipher:void 0,mac:void 0,compress:void 0,lang:void 0},all:void 0},s=0;for(let a of n){let c,f,l,u;if(typeof a=="string")c=r,f=e[a],l=u=a;else{let g=a[0];c=r[g],u=a[1],f=e[g][u],l=`${g}.${u}`}let h={array:void 0,buffer:void 0};if(Buffer.isBuffer(f))h.array=(""+f).split(","),h.buffer=f,s+=4+f.length;else{if(typeof f=="string"&&(f=f.split(",")),Array.isArray(f))h.array=f,h.buffer=Buffer.from(f.join(","));else throw new TypeError(`Invalid \`${l}\` type: ${typeof f}`);s+=4+h.buffer.length}c[u]=h}let i=Buffer.allocUnsafe(s);r.all=i;let o=0;for(let a of n){let c;typeof a=="string"?c=r[a].buffer:c=r[a[0]][a[1]].buffer,o=Ot(i,c.length,o),i.set(c,o),o+=c.length}this.totalSize=s,this.lists=r}copyAllTo(e,r){let s=this.lists.all;if(typeof r!="number")throw new TypeError(`Invalid offset value: ${typeof r}`);if(e.length-r<s.length)throw new Error("Insufficient space to copy list");return e.set(s,r),s.length}}})(),yn=(()=>{let n=Buffer.allocUnsafe(4);return(t,e)=>{Ot(n,e.length,0),t.update(n),t.update(e)}})();function Tr(n,t,e,r,s,i){let o;if(n){let a=ca(t).update(e).update(r).update(i).update(s).digest();for(;a.length<n;){let c=ca(t).update(e).update(r).update(a).digest(),f=Buffer.allocUnsafe(a.length+c.length);f.set(a,0),f.set(c,a.length),a=f}a.length===n?o=a:o=new lg(a.buffer,a.byteOffset,n)}else o=pg;return o}function Pf(n,t){if(t.length===0){this._debug&&this._debug("Inbound: Skipping empty packet payload");return}if(this._skipNextInboundPacket){this._skipNextInboundPacket=!1;return}t=this._packetRW.read.read(t);let e=t[0];if(!this._strictMode)switch(e){case lt.IGNORE:case lt.UNIMPLEMENTED:case lt.DEBUG:return Pr||(Pr=us()),Pr[e](this,t)}switch(e){case lt.DISCONNECT:return Pr||(Pr=us()),Pr[e](this,t);case lt.KEXINIT:return n.firstPacket?(n.firstPacket=!1,Nf(this,t)):Ye(this,"Received extra KEXINIT during handshake","handshake",Ge.KEY_EXCHANGE_FAILED);default:if(e<20||e>49)return Ye(this,`Received unexpected packet type ${e}`,"handshake",Ge.KEY_EXCHANGE_FAILED)}return this._kex.parse(t)}function mg(n){let t=Lr[n.cs.cipher],e=Lr[n.sc.cipher],r=Math.max(0,t.sslName==="des-ede3-cbc"?14:t.keyLen,t.blockLen,t.ivLen,e.sslName==="des-ede3-cbc"?14:e.keyLen,e.blockLen,e.ivLen)*8;return r<=112?2048:r<=128?3072:r<=192?7680:8192}function Es(n){if(!n._sentNEWKEYS){n._protocol._debug&&n._protocol._debug("Outbound: Sending NEWKEYS");let t=n._protocol._packetRW.write.allocStartKEX,e=n._protocol._packetRW.write.alloc(1,!0);e[t]=lt.NEWKEYS,n._protocol._cipher.encrypt(n._protocol._packetRW.write.finalize(e,!0)),n._sentNEWKEYS=!0,n._protocol._strictMode&&(n._protocol._cipher.outSeqno=0)}}Tf.exports={KexInit:aa,kexinit:Rf,onKEXPayload:Pf,DEFAULT_KEXINIT_CLIENT:new aa({kex:If.concat(["ext-info-c","kex-strict-c-v00@openssh.com"]),serverHostKey:Cf,cs:{cipher:hs,mac:ps,compress:gs,lang:[]},sc:{cipher:hs,mac:ps,compress:gs,lang:[]}}),DEFAULT_KEXINIT_SERVER:new aa({kex:If.concat(["kex-strict-s-v00@openssh.com"]),serverHostKey:Cf,cs:{cipher:hs,mac:ps,compress:gs,lang:[]},sc:{cipher:hs,mac:ps,compress:gs,lang:[]}}),HANDLERS:{[lt.KEXINIT]:Nf}}});var Lf=at((SE,Ag)=>{Ag.exports={name:"ssh2",version:"1.17.0",author:"Brian White <mscdex@mscdex.net>",description:"SSH2 client and server modules written in pure JavaScript for node.js",main:"./lib/index.js",engines:{node:">=10.16.0"},dependencies:{asn1:"^0.2.6","bcrypt-pbkdf":"^1.0.2"},devDependencies:{"@mscdex/eslint-config":"^1.1.0",eslint:"^7.32.0"},optionalDependencies:{"cpu-features":"~0.0.10",nan:"^2.23.0"},scripts:{install:"node install.js",rebuild:"node install.js",test:"node test/test.js",lint:"eslint --cache --report-unused-disable-directives --ext=.js .eslintrc.js examples lib test","lint:fix":"npm run lint -- --fix"},keywords:["ssh","ssh2","sftp","secure","shell","exec","remote","client"],licenses:[{type:"MIT",url:"http://github.com/mscdex/ssh2/raw/master/LICENSE"}],repository:{type:"git",url:"http://github.com/mscdex/ssh2.git"}}});var ha=at((wE,Gf)=>{"use strict";var{inspect:Ff}=require("util"),{bindingAvailable:Eg,NullCipher:_g,NullDecipher:yg}=Qn(),{COMPAT_CHECKS:bg,DISCONNECT_REASON:Hf,eddsaSupported:xg,MESSAGE:Se,SIGNALS:Uf,TERMINAL_MODE:ua}=Pn(),{DEFAULT_KEXINIT_CLIENT:Sg,DEFAULT_KEXINIT_SERVER:wg,KexInit:Df,kexinit:Qf,onKEXPayload:Ig}=ds(),{parseKey:Of}=Kn(),Cg=us(),{bufferCopy:_s,bufferFill:vg,bufferSlice:Wf,convertSignature:Mf,sendPacket:we,writeUInt32BE:B}=dn(),{PacketReader:kg,PacketWriter:Bg,ZlibPacketReader:qf,ZlibPacketWriter:Kf}=ia(),Rg=Lf().version,Ng=new Map(Object.values(Hf).map(n=>[n,1])),Vf=Buffer.from(`SSH-2.0-ssh2js${Rg}`),Pg=Buffer.from(`${Vf}\r
|
|
7
|
+
`),Tg=8192,Lg=1024,$f=Buffer.from([Se.GLOBAL_REQUEST,0,0,0,21,107,101,101,112,97,108,105,118,101,64,111,112,101,110,115,115,104,46,99,111,109,1]),Ug=Buffer.from([ua.TTY_OP_END]);function la(){}var da=class{constructor(t){let e=t.onWrite;if(typeof e!="function")throw new Error("Missing onWrite function");this._onWrite=g=>{e(g)};let r=t.onError;if(typeof r!="function")throw new Error("Missing onError function");this._onError=g=>{r(g)};let s=t.debug;this._debug=typeof s=="function"?g=>{s(g)}:void 0;let i=t.onHeader;this._onHeader=typeof i=="function"?(...g)=>{i(...g)}:la;let o=t.onPacket;this._onPacket=typeof o=="function"?()=>{o()}:la;let a=t.onHandshakeComplete;typeof a!="function"&&(a=la);let c;this._onHandshakeComplete=(...g)=>{this._debug&&this._debug("Handshake completed"),c===void 0?c=!0:c=!1;let y=this._queue;if(y){this._queue=void 0,this._debug&&this._debug(`Draining outbound queue (${y.length}) ...`);for(let _=0;_<y.length;++_){let b=y[_],C=this._packetRW.write.finalize(b);if(C===b){let L=this._cipher.allocPacket(b.length);L.set(b,5),C=L}we(this,C)}this._debug&&this._debug("... finished draining outbound queue")}c&&this._server&&this._kex.remoteExtInfoEnabled&&Qg(this),a(...g)},this._queue=void 0;let f=t.messageHandlers;typeof f=="object"&&f!==null?this._handlers=f:this._handlers={},this._onPayload=$g.bind(this),this._server=!!t.server,this._banner=void 0;let l;if(this._server){if(typeof t.hostKeys!="object"||t.hostKeys===null)throw new Error("Missing server host key(s)");this._hostKeys=t.hostKeys,typeof t.greeting=="string"&&t.greeting.length&&(l=t.greeting.slice(-2)===`\r
|
|
8
8
|
`?t.greeting:`${t.greeting}\r
|
|
9
9
|
`),typeof t.banner=="string"&&t.banner.length&&(this._banner=t.banner.slice(-2)===`\r
|
|
10
10
|
`?t.banner:`${t.banner}\r
|
|
11
|
-
`)}else this._hostKeys=void 0;let u=t.offer;typeof u!="object"||u===null?u=this._server?O0:D0:u.constructor!==Ad&&(this._server?u.kex=u.kex.concat(["kex-strict-s-v00@openssh.com"]):u.kex=u.kex.concat(["ext-info-c","kex-strict-c-v00@openssh.com"]),u=new Ad(u)),this._kex=void 0,this._strictMode=void 0,this._kexinit=void 0,this._offer=u,this._cipher=new P0(0,this._onWrite),this._decipher=void 0,this._skipNextInboundPacket=!1,this._packetRW={read:new H0,write:new Q0(this)},this._hostVerifier=!this._server&&typeof t.hostVerifier=="function"?t.hostVerifier:void 0,this._parse=j0,this._buffer=void 0,this._authsQueue=[],this._authenticated=!1,this._remoteIdentRaw=void 0;let h;if(typeof t.ident=="string")this._identRaw=Buffer.from(`SSH-2.0-${t.ident}`),h=Buffer.allocUnsafe(this._identRaw.length+2),h.set(this._identRaw,0),h[h.length-2]=13,h[h.length-1]=10;else if(Buffer.isBuffer(t.ident)){let g=Buffer.allocUnsafe(8+t.ident.length);g.latin1Write("SSH-2.0-",0,8),g.set(t.ident,8),this._identRaw=g,h=Buffer.allocUnsafe(g.length+2),h.set(g,0),h[h.length-2]=13,h[h.length-1]=10}else this._identRaw=vd,h=K0;this._compatFlags=0,this._debug&&(N0?this._debug("Custom crypto binding available"):this._debug("Custom crypto binding not available")),this._debug&&this._debug(`Local ident: ${bd(this._identRaw.toString())}`),this.start=()=>{this.start=void 0,l&&this._onWrite(l),this._onWrite(h)}}_destruct(t){this._packetRW.read.cleanup(),this._packetRW.write.cleanup(),this._cipher&&this._cipher.free(),this._decipher&&this._decipher.free(),(typeof t!="string"||t.length===0)&&(t="fatal error"),this.parse=()=>{throw new Error(`Instance unusable after ${t}`)},this._onWrite=()=>{throw new Error(`Instance unusable after ${t}`)},this._destruct=void 0}cleanup(){this._destruct&&this._destruct()}parse(t,e,r){for(;e<r;)e=this._parse(t,e,r)}disconnect(t){let r=this._packetRW.write.allocStartKEX,s=this._packetRW.write.alloc(13,!0),i=r+13;q0.has(t)||(t=xd.PROTOCOL_ERROR),s[r]=Se.DISCONNECT,B(s,t,++r),s.fill(0,r+=4,i),this._debug&&this._debug(`Outbound: Sending DISCONNECT (${t})`),we(this,this._packetRW.write.finalize(s,!0),!0)}ping(){let t=this._packetRW.write.allocStart,e=this._packetRW.write.alloc(yd.length);e.set(yd,t),this._debug&&this._debug("Outbound: Sending ping (GLOBAL_REQUEST: keepalive@openssh.com)"),we(this,this._packetRW.write.finalize(e))}rekey(){this._kexinit===void 0?(this._debug&&this._debug("Outbound: Initiated explicit rekey"),this._queue=[],Sd(this)):this._debug&&this._debug("Outbound: Ignoring rekey during handshake")}requestSuccess(t){let e=this._packetRW.write.allocStart,r;Buffer.isBuffer(t)?(r=this._packetRW.write.alloc(1+t.length),r[e]=Se.REQUEST_SUCCESS,r.set(t,++e)):(r=this._packetRW.write.alloc(1),r[e]=Se.REQUEST_SUCCESS),this._debug&&this._debug("Outbound: Sending REQUEST_SUCCESS"),we(this,this._packetRW.write.finalize(r))}requestFailure(){let t=this._packetRW.write.allocStart,e=this._packetRW.write.alloc(1);e[t]=Se.REQUEST_FAILURE,this._debug&&this._debug("Outbound: Sending REQUEST_FAILURE"),we(this,this._packetRW.write.finalize(e))}channelSuccess(t){let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(5);r[e]=Se.CHANNEL_SUCCESS,B(r,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_SUCCESS (r:${t})`),we(this,this._packetRW.write.finalize(r))}channelFailure(t){let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(5);r[e]=Se.CHANNEL_FAILURE,B(r,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_FAILURE (r:${t})`),we(this,this._packetRW.write.finalize(r))}channelEOF(t){let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(5);r[e]=Se.CHANNEL_EOF,B(r,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_EOF (r:${t})`),we(this,this._packetRW.write.finalize(r))}channelClose(t){let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(5);r[e]=Se.CHANNEL_CLOSE,B(r,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_CLOSE (r:${t})`),we(this,this._packetRW.write.finalize(r))}channelWindowAdjust(t,e){let r=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(9);s[r]=Se.CHANNEL_WINDOW_ADJUST,B(s,t,++r),B(s,e,r+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_WINDOW_ADJUST (r:${t}, ${e})`),we(this,this._packetRW.write.finalize(s))}channelData(t,e){let r=Buffer.isBuffer(e),s=r?e.length:Buffer.byteLength(e),i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(9+s);o[i]=Se.CHANNEL_DATA,B(o,t,++i),B(o,s,i+=4),r?o.set(e,i+=4):o.utf8Write(e,i+=4,s),this._debug&&this._debug(`Outbound: Sending CHANNEL_DATA (r:${t}, ${s})`),we(this,this._packetRW.write.finalize(o))}channelExtData(t,e,r){let s=Buffer.isBuffer(e),i=s?e.length:Buffer.byteLength(e),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(13+i);a[o]=Se.CHANNEL_EXTENDED_DATA,B(a,t,++o),B(a,r,o+=4),B(a,i,o+=4),s?a.set(e,o+=4):a.utf8Write(e,o+=4,i),this._debug&&this._debug(`Outbound: Sending CHANNEL_EXTENDED_DATA (r:${t})`),we(this,this._packetRW.write.finalize(a))}channelOpenConfirm(t,e,r,s){let i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(17);o[i]=Se.CHANNEL_OPEN_CONFIRMATION,B(o,t,++i),B(o,e,i+=4),B(o,r,i+=4),B(o,s,i+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN_CONFIRMATION (r:${t}, l:${e})`),we(this,this._packetRW.write.finalize(o))}channelOpenFail(t,e,r){typeof r!="string"&&(r="");let s=Buffer.byteLength(r),i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(13+s+4);o[i]=Se.CHANNEL_OPEN_FAILURE,B(o,t,++i),B(o,e,i+=4),B(o,s,i+=4),i+=4,s&&(o.utf8Write(r,i,s),i+=s),B(o,0,i),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN_FAILURE (r:${t})`),we(this,this._packetRW.write.finalize(o))}service(t){if(this._server)throw new Error("Client-only method called in server mode");let e=Buffer.byteLength(t),r=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(5+e);s[r]=Se.SERVICE_REQUEST,B(s,e,++r),s.utf8Write(t,r+=4,e),this._debug&&this._debug(`Outbound: Sending SERVICE_REQUEST (${t})`),we(this,this._packetRW.write.finalize(s))}authPassword(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let s=Buffer.byteLength(t),i=Buffer.byteLength(e),o=r?Buffer.byteLength(r):0,a=this._packetRW.write.allocStart,c=this._packetRW.write.alloc(5+s+4+14+4+8+1+4+i+(r?4+o:0));c[a]=Se.USERAUTH_REQUEST,B(c,s,++a),c.utf8Write(t,a+=4,s),B(c,14,a+=s),c.utf8Write("ssh-connection",a+=4,14),B(c,8,a+=14),c.utf8Write("password",a+=4,8),c[a+=8]=r?1:0,B(c,i,++a),Buffer.isBuffer(e)?Ds(e,c,0,i,a+=4):c.utf8Write(e,a+=4,i),r?(B(c,o,a+=i),Buffer.isBuffer(r)?Ds(r,c,0,o,a+=4):c.utf8Write(r,a+=4,o),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (changed password)")):this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (password)"),this._authsQueue.push("password"),we(this,this._packetRW.write.finalize(c))}authPK(t,e,r,s){if(this._server)throw new Error("Client-only method called in server mode");if(e=Ed(e),e instanceof Error)throw new Error("Invalid key");let i=e.type;e=e.getPublicSSH(),typeof r=="function"&&(s=r,r=void 0),r||(r=i);let o=Buffer.byteLength(t),a=Buffer.byteLength(r),c=e.length,f=this._kex.sessionID,l=f.length,u=(s?4+l:0)+1+4+o+4+14+4+9+1+4+a+4+c,h,g;if(s?(h=Buffer.allocUnsafe(u),g=0,B(h,l,g),h.set(f,g+=4),g+=l):(h=this._packetRW.write.alloc(u),g=this._packetRW.write.allocStart),h[g]=Se.USERAUTH_REQUEST,B(h,o,++g),h.utf8Write(t,g+=4,o),B(h,14,g+=o),h.utf8Write("ssh-connection",g+=4,14),B(h,9,g+=14),h.utf8Write("publickey",g+=4,9),h[g+=9]=s?1:0,B(h,a,++g),h.utf8Write(r,g+=4,a),B(h,c,g+=a),h.set(e,g+=4),!s){this._authsQueue.push("publickey"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (publickey -- check)"),we(this,this._packetRW.write.finalize(h));return}s(h,y=>{if(y=_d(y,i),y===!1)throw new Error("Error while converting handshake signature");let _=y.length;g=this._packetRW.write.allocStart,h=this._packetRW.write.alloc(5+o+4+14+4+9+1+4+a+4+c+4+4+a+4+_),h[g]=Se.USERAUTH_REQUEST,B(h,o,++g),h.utf8Write(t,g+=4,o),B(h,14,g+=o),h.utf8Write("ssh-connection",g+=4,14),B(h,9,g+=14),h.utf8Write("publickey",g+=4,9),h[g+=9]=1,B(h,a,++g),h.utf8Write(r,g+=4,a),B(h,c,g+=a),h.set(e,g+=4),B(h,4+a+4+_,g+=c),B(h,a,g+=4),h.utf8Write(r,g+=4,a),B(h,_,g+=a),h.set(y,g+=4),this._authsQueue.push("publickey"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (publickey)"),we(this,this._packetRW.write.finalize(h))})}authHostbased(t,e,r,s,i,o){if(this._server)throw new Error("Client-only method called in server mode");if(e=Ed(e),e instanceof Error)throw new Error("Invalid key");let a=e.type;e=e.getPublicSSH(),typeof i=="function"&&(o=i,i=void 0),i||(i=a);let c=Buffer.byteLength(t),f=Buffer.byteLength(i),l=e.length,u=this._kex.sessionID,h=u.length,g=Buffer.byteLength(r),y=Buffer.byteLength(s),_=Buffer.allocUnsafe(4+h+1+4+c+4+14+4+9+4+f+4+l+4+g+4+y),b=0;B(_,h,b),_.set(u,b+=4),_[b+=h]=Se.USERAUTH_REQUEST,B(_,c,++b),_.utf8Write(t,b+=4,c),B(_,14,b+=c),_.utf8Write("ssh-connection",b+=4,14),B(_,9,b+=14),_.utf8Write("hostbased",b+=4,9),B(_,f,b+=9),_.utf8Write(i,b+=4,f),B(_,l,b+=f),_.set(e,b+=4),B(_,g,b+=l),_.utf8Write(r,b+=4,g),B(_,y,b+=g),_.utf8Write(s,b+=4,y),o(_,C=>{if(C=_d(C,a),!C)throw new Error("Error while converting handshake signature");let L=C.length,F=_.length-h-4;b=this._packetRW.write.allocStart;let k=this._packetRW.write.alloc(F+4+4+f+4+L);Ds(_,k,4+h,_.length,b),B(k,4+f+4+L,b+=F),B(k,f,b+=4),k.utf8Write(i,b+=4,f),B(k,L,b+=f),k.set(C,b+=4),this._authsQueue.push("hostbased"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (hostbased)"),we(this,this._packetRW.write.finalize(k))})}authKeyboard(t){if(this._server)throw new Error("Client-only method called in server mode");let e=Buffer.byteLength(t),r=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(5+e+4+14+4+20+4+4);s[r]=Se.USERAUTH_REQUEST,B(s,e,++r),s.utf8Write(t,r+=4,e),B(s,14,r+=e),s.utf8Write("ssh-connection",r+=4,14),B(s,20,r+=14),s.utf8Write("keyboard-interactive",r+=4,20),B(s,0,r+=20),B(s,0,r+=4),this._authsQueue.push("keyboard-interactive"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (keyboard-interactive)"),we(this,this._packetRW.write.finalize(s))}authNone(t){if(this._server)throw new Error("Client-only method called in server mode");let e=Buffer.byteLength(t),r=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(5+e+4+14+4+4);s[r]=Se.USERAUTH_REQUEST,B(s,e,++r),s.utf8Write(t,r+=4,e),B(s,14,r+=e),s.utf8Write("ssh-connection",r+=4,14),B(s,4,r+=14),s.utf8Write("none",r+=4,4),this._authsQueue.push("none"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (none)"),we(this,this._packetRW.write.finalize(s))}authInfoRes(t){if(this._server)throw new Error("Client-only method called in server mode");let e=0,r;if(t){r=new Array(t.length);for(let o=0;o<t.length;++o){let a=Buffer.byteLength(t[o]);r[o]=a,e+=4+a}}let s=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(5+e);if(i[s]=Se.USERAUTH_INFO_RESPONSE,t){B(i,t.length,++s),s+=4;for(let o=0;o<t.length;++o){let a=r[o];B(i,a,s),s+=4,a&&(i.utf8Write(t[o],s,a),s+=a)}}else B(i,0,++s);this._debug&&this._debug("Outbound: Sending USERAUTH_INFO_RESPONSE"),we(this,this._packetRW.write.finalize(i))}tcpipForward(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let s=Buffer.byteLength(t),i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(23+s+4);o[i]=Se.GLOBAL_REQUEST,B(o,13,++i),o.utf8Write("tcpip-forward",i+=4,13),o[i+=13]=r===void 0||r===!0?1:0,B(o,s,++i),o.utf8Write(t,i+=4,s),B(o,e,i+=s),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (tcpip-forward)"),we(this,this._packetRW.write.finalize(o))}cancelTcpipForward(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let s=Buffer.byteLength(t),i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(30+s+4);o[i]=Se.GLOBAL_REQUEST,B(o,20,++i),o.utf8Write("cancel-tcpip-forward",i+=4,20),o[i+=20]=r===void 0||r===!0?1:0,B(o,s,++i),o.utf8Write(t,i+=4,s),B(o,e,i+=s),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (cancel-tcpip-forward)"),we(this,this._packetRW.write.finalize(o))}openssh_streamLocalForward(t,e){if(this._server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),s=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(41+r);i[s]=Se.GLOBAL_REQUEST,B(i,31,++s),i.utf8Write("streamlocal-forward@openssh.com",s+=4,31),i[s+=31]=e===void 0||e===!0?1:0,B(i,r,++s),i.utf8Write(t,s+=4,r),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (streamlocal-forward@openssh.com)"),we(this,this._packetRW.write.finalize(i))}openssh_cancelStreamLocalForward(t,e){if(this._server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),s=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(48+r);i[s]=Se.GLOBAL_REQUEST,B(i,38,++s),i.utf8Write("cancel-streamlocal-forward@openssh.com",s+=4,38),i[s+=38]=e===void 0||e===!0?1:0,B(i,r,++s),i.utf8Write(t,s+=4,r),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (cancel-streamlocal-forward@openssh.com)"),we(this,this._packetRW.write.finalize(i))}directTcpip(t,e,r,s){if(this._server)throw new Error("Client-only method called in server mode");let i=Buffer.byteLength(s.srcIP),o=Buffer.byteLength(s.dstIP),a=this._packetRW.write.allocStart,c=this._packetRW.write.alloc(33+i+4+4+o+4);c[a]=Se.CHANNEL_OPEN,B(c,12,++a),c.utf8Write("direct-tcpip",a+=4,12),B(c,t,a+=12),B(c,e,a+=4),B(c,r,a+=4),B(c,o,a+=4),c.utf8Write(s.dstIP,a+=4,o),B(c,s.dstPort,a+=o),B(c,i,a+=4),c.utf8Write(s.srcIP,a+=4,i),B(c,s.srcPort,a+=i),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, direct-tcpip)`),we(this,this._packetRW.write.finalize(c))}openssh_directStreamLocal(t,e,r,s){if(this._server)throw new Error("Client-only method called in server mode");let i=Buffer.byteLength(s.socketPath),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(51+i+4+4);a[o]=Se.CHANNEL_OPEN,B(a,30,++o),a.utf8Write("direct-streamlocal@openssh.com",o+=4,30),B(a,t,o+=30),B(a,e,o+=4),B(a,r,o+=4),B(a,i,o+=4),a.utf8Write(s.socketPath,o+=4,i),F0(a,0,o+=i,o+8),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, direct-streamlocal@openssh.com)`),we(this,this._packetRW.write.finalize(a))}openssh_noMoreSessions(t){if(this._server)throw new Error("Client-only method called in server mode");let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(34);r[e]=Se.GLOBAL_REQUEST,B(r,28,++e),r.utf8Write("no-more-sessions@openssh.com",e+=4,28),r[e+=28]=t===void 0||t===!0?1:0,this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (no-more-sessions@openssh.com)"),we(this,this._packetRW.write.finalize(r))}session(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let s=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(24);i[s]=Se.CHANNEL_OPEN,B(i,7,++s),i.utf8Write("session",s+=4,7),B(i,t,s+=7),B(i,e,s+=4),B(i,r,s+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, session)`),we(this,this._packetRW.write.finalize(i))}windowChange(t,e,r,s,i){if(this._server)throw new Error("Client-only method called in server mode");let o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(39);a[o]=Se.CHANNEL_REQUEST,B(a,t,++o),B(a,13,o+=4),a.utf8Write("window-change",o+=4,13),a[o+=13]=0,B(a,r,++o),B(a,e,o+=4),B(a,i,o+=4),B(a,s,o+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, window-change)`),we(this,this._packetRW.write.finalize(a))}pty(t,e,r,s,i,o,a,c){if(this._server)throw new Error("Client-only method called in server mode");(!o||!o.length)&&(o="vt100"),a&&!Buffer.isBuffer(a)&&!Array.isArray(a)&&typeof a=="object"&&a!==null&&(a=em(a)),(!a||!a.length)&&(a=Y0);let f=o.length,l=a.length,u=this._packetRW.write.allocStart,h=this._packetRW.write.alloc(21+f+4+4+4+4+4+l);if(h[u]=Se.CHANNEL_REQUEST,B(h,t,++u),B(h,7,u+=4),h.utf8Write("pty-req",u+=4,7),h[u+=7]=c===void 0||c===!0?1:0,B(h,f,++u),h.utf8Write(o,u+=4,f),B(h,r,u+=f),B(h,e,u+=4),B(h,i,u+=4),B(h,s,u+=4),B(h,l,u+=4),u+=4,Array.isArray(a))for(let g=0;g<l;++g)h[u++]=a[g];else Buffer.isBuffer(a)&&h.set(a,u);this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, pty-req)`),we(this,this._packetRW.write.finalize(h))}shell(t,e){if(this._server)throw new Error("Client-only method called in server mode");let r=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(15);s[r]=Se.CHANNEL_REQUEST,B(s,t,++r),B(s,5,r+=4),s.utf8Write("shell",r+=4,5),s[r+=5]=e===void 0||e===!0?1:0,this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, shell)`),we(this,this._packetRW.write.finalize(s))}exec(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let s=Buffer.isBuffer(e),i=s?e.length:Buffer.byteLength(e),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(18+i);a[o]=Se.CHANNEL_REQUEST,B(a,t,++o),B(a,4,o+=4),a.utf8Write("exec",o+=4,4),a[o+=4]=r===void 0||r===!0?1:0,B(a,i,++o),s?a.set(e,o+=4):a.utf8Write(e,o+=4,i),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, exec: ${e})`),we(this,this._packetRW.write.finalize(a))}signal(t,e){if(this._server)throw new Error("Client-only method called in server mode");let r=e;if(e=e.toUpperCase(),e.slice(0,3)==="SIG"&&(e=e.slice(3)),md[e]!==1)throw new Error(`Invalid signal: ${r}`);let s=e.length,i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(20+s);o[i]=Se.CHANNEL_REQUEST,B(o,t,++i),B(o,6,i+=4),o.utf8Write("signal",i+=4,6),o[i+=6]=0,B(o,s,++i),o.utf8Write(e,i+=4,s),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, signal: ${e})`),we(this,this._packetRW.write.finalize(o))}env(t,e,r,s){if(this._server)throw new Error("Client-only method called in server mode");let i=Buffer.byteLength(e),o=Buffer.isBuffer(r),a=o?r.length:Buffer.byteLength(r),c=this._packetRW.write.allocStart,f=this._packetRW.write.alloc(17+i+4+a);f[c]=Se.CHANNEL_REQUEST,B(f,t,++c),B(f,3,c+=4),f.utf8Write("env",c+=4,3),f[c+=3]=s===void 0||s===!0?1:0,B(f,i,++c),f.utf8Write(e,c+=4,i),B(f,a,c+=i),o?f.set(r,c+=4):f.utf8Write(r,c+=4,a),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, env: ${e}=${r})`),we(this,this._packetRW.write.finalize(f))}x11Forward(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let s=e.protocol,i=e.cookie,o=Buffer.isBuffer(s),a=o?s.length:Buffer.byteLength(s),c=Buffer.isBuffer(i),f=c?i.length:Buffer.byteLength(i),l=this._packetRW.write.allocStart,u=this._packetRW.write.alloc(22+a+4+f+4);u[l]=Se.CHANNEL_REQUEST,B(u,t,++l),B(u,7,l+=4),u.utf8Write("x11-req",l+=4,7),u[l+=7]=r===void 0||r===!0?1:0,u[++l]=e.single?1:0,B(u,a,++l),o?u.set(s,l+=4):u.utf8Write(s,l+=4,a),B(u,f,l+=a),c?u.set(i,l+=4):u.latin1Write(i,l+=4,f),B(u,e.screen||0,l+=f),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, x11-req)`),we(this,this._packetRW.write.finalize(u))}subsystem(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let s=Buffer.byteLength(e),i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(23+s);o[i]=Se.CHANNEL_REQUEST,B(o,t,++i),B(o,9,i+=4),o.utf8Write("subsystem",i+=4,9),o[i+=9]=r===void 0||r===!0?1:0,B(o,s,++i),o.utf8Write(e,i+=4,s),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, subsystem: ${e})`),we(this,this._packetRW.write.finalize(o))}openssh_agentForward(t,e){if(this._server)throw new Error("Client-only method called in server mode");let r=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(36);s[r]=Se.CHANNEL_REQUEST,B(s,t,++r),B(s,26,r+=4),s.utf8Write("auth-agent-req@openssh.com",r+=4,26),s[r+=26]=e===void 0||e===!0?1:0,this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, auth-agent-req@openssh.com)`),we(this,this._packetRW.write.finalize(s))}openssh_hostKeysProve(t){if(this._server)throw new Error("Client-only method called in server mode");let e=0,r=[];for(let o of t){let a=o.getPublicSSH();e+=4+a.length,r.push(a)}let s=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(35+e);i[s]=Se.GLOBAL_REQUEST,B(i,29,++s),i.utf8Write("hostkeys-prove-00@openssh.com",s+=4,29),i[s+=29]=1,++s;for(let o of r)B(i,o.length,s),Ds(o,i,0,o.length,s+=4),s+=o.length;this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (hostkeys-prove-00@openssh.com)"),we(this,this._packetRW.write.finalize(i))}serviceAccept(t){if(!this._server)throw new Error("Server-only method called in client mode");let e=Buffer.byteLength(t),r=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(5+e);if(s[r]=Se.SERVICE_ACCEPT,B(s,e,++r),s.utf8Write(t,r+=4,e),this._debug&&this._debug(`Outbound: Sending SERVICE_ACCEPT (${t})`),we(this,this._packetRW.write.finalize(s)),this._server&&this._banner&&t==="ssh-userauth"){let i=this._banner;this._banner=void 0;let o=Buffer.byteLength(i);r=this._packetRW.write.allocStart;let a=this._packetRW.write.alloc(5+o+4);a[r]=Se.USERAUTH_BANNER,B(a,o,++r),a.utf8Write(i,r+=4,o),B(a,0,r+=o),this._debug&&this._debug("Outbound: Sending USERAUTH_BANNER"),we(this,this._packetRW.write.finalize(a))}}forwardedTcpip(t,e,r,s){if(!this._server)throw new Error("Server-only method called in client mode");let i=Buffer.byteLength(s.boundAddr),o=Buffer.byteLength(s.remoteAddr),a=this._packetRW.write.allocStart,c=this._packetRW.write.alloc(36+i+4+4+o+4);c[a]=Se.CHANNEL_OPEN,B(c,15,++a),c.utf8Write("forwarded-tcpip",a+=4,15),B(c,t,a+=15),B(c,e,a+=4),B(c,r,a+=4),B(c,i,a+=4),c.utf8Write(s.boundAddr,a+=4,i),B(c,s.boundPort,a+=i),B(c,o,a+=4),c.utf8Write(s.remoteAddr,a+=4,o),B(c,s.remotePort,a+=o),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, forwarded-tcpip)`),we(this,this._packetRW.write.finalize(c))}x11(t,e,r,s){if(!this._server)throw new Error("Server-only method called in client mode");let i=Buffer.byteLength(s.originAddr),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(24+i+4);a[o]=Se.CHANNEL_OPEN,B(a,3,++o),a.utf8Write("x11",o+=4,3),B(a,t,o+=3),B(a,e,o+=4),B(a,r,o+=4),B(a,i,o+=4),a.utf8Write(s.originAddr,o+=4,i),B(a,s.originPort,o+=i),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, x11)`),we(this,this._packetRW.write.finalize(a))}openssh_authAgent(t,e,r){if(!this._server)throw new Error("Server-only method called in client mode");let s=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(39);i[s]=Se.CHANNEL_OPEN,B(i,22,++s),i.utf8Write("auth-agent@openssh.com",s+=4,22),B(i,t,s+=22),B(i,e,s+=4),B(i,r,s+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, auth-agent@openssh.com)`),we(this,this._packetRW.write.finalize(i))}openssh_forwardedStreamLocal(t,e,r,s){if(!this._server)throw new Error("Server-only method called in client mode");let i=Buffer.byteLength(s.socketPath),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(54+i+4);a[o]=Se.CHANNEL_OPEN,B(a,33,++o),a.utf8Write("forwarded-streamlocal@openssh.com",o+=4,33),B(a,t,o+=33),B(a,e,o+=4),B(a,r,o+=4),B(a,i,o+=4),a.utf8Write(s.socketPath,o+=4,i),B(a,0,o+=i),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, forwarded-streamlocal@openssh.com)`),we(this,this._packetRW.write.finalize(a))}exitStatus(t,e){if(!this._server)throw new Error("Server-only method called in client mode");let r=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(25);s[r]=Se.CHANNEL_REQUEST,B(s,t,++r),B(s,11,r+=4),s.utf8Write("exit-status",r+=4,11),s[r+=11]=0,B(s,e,++r),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, exit-status: ${e})`),we(this,this._packetRW.write.finalize(s))}exitSignal(t,e,r,s){if(!this._server)throw new Error("Server-only method called in client mode");let i=e;if(typeof i!="string"||!i)throw new Error(`Invalid signal: ${i}`);let o=e.toUpperCase();if(o.slice(0,3)==="SIG"&&(o=o.slice(3)),md[o]!==1)throw new Error(`Invalid signal: ${i}`);let a=Buffer.byteLength(o),c=s?Buffer.byteLength(s):0,f=this._packetRW.write.allocStart,l=this._packetRW.write.alloc(25+a+1+4+c+4);l[f]=Se.CHANNEL_REQUEST,B(l,t,++f),B(l,11,f+=4),l.utf8Write("exit-signal",f+=4,11),l[f+=11]=0,B(l,a,++f),l.utf8Write(o,f+=4,a),l[f+=a]=r?1:0,B(l,c,++f),f+=4,c&&(l.utf8Write(s,f,c),f+=c),B(l,0,f),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, exit-signal: ${e})`),we(this,this._packetRW.write.finalize(l))}authFailure(t,e){if(!this._server)throw new Error("Server-only method called in client mode");if(this._authsQueue.length===0)throw new Error("No auth in progress");let r;if(typeof t=="boolean"&&(e=t,t=void 0),t){r=[];for(let a=0;a<t.length;++a)t[a].toLowerCase()!=="none"&&r.push(t[a]);r=r.join(",")}else r="";let s=r.length,i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(5+s+1);o[i]=Se.USERAUTH_FAILURE,B(o,s,++i),o.utf8Write(r,i+=4,s),o[i+=s]=e===!0?1:0,this._authsQueue.shift(),this._debug&&this._debug("Outbound: Sending USERAUTH_FAILURE"),we(this,this._packetRW.write.finalize(o))}authSuccess(){if(!this._server)throw new Error("Server-only method called in client mode");if(this._authsQueue.length===0)throw new Error("No auth in progress");let t=this._packetRW.write.allocStart,e=this._packetRW.write.alloc(1);e[t]=Se.USERAUTH_SUCCESS,this._authsQueue.shift(),this._authenticated=!0,this._debug&&this._debug("Outbound: Sending USERAUTH_SUCCESS"),we(this,this._packetRW.write.finalize(e)),this._kex.negotiated.cs.compress==="zlib@openssh.com"&&(this._packetRW.read=new Id),this._kex.negotiated.sc.compress==="zlib@openssh.com"&&(this._packetRW.write=new Cd(this))}authPKOK(t,e){if(!this._server)throw new Error("Server-only method called in client mode");if(this._authsQueue.length===0||this._authsQueue[0]!=="publickey")throw new Error('"publickey" auth not in progress');let r=Buffer.byteLength(t),s=e.length,i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(5+r+4+s);o[i]=Se.USERAUTH_PK_OK,B(o,r,++i),o.utf8Write(t,i+=4,r),B(o,s,i+=r),o.set(e,i+=4),this._authsQueue.shift(),this._debug&&this._debug("Outbound: Sending USERAUTH_PK_OK"),we(this,this._packetRW.write.finalize(o))}authPasswdChg(t){if(!this._server)throw new Error("Server-only method called in client mode");let e=Buffer.byteLength(t),r=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(5+e+4);s[r]=Se.USERAUTH_PASSWD_CHANGEREQ,B(s,e,++r),s.utf8Write(t,r+=4,e),B(s,0,r+=e),this._debug&&this._debug("Outbound: Sending USERAUTH_PASSWD_CHANGEREQ"),we(this,this._packetRW.write.finalize(s))}authInfoReq(t,e,r){if(!this._server)throw new Error("Server-only method called in client mode");let s=0,i=t?Buffer.byteLength(t):0,o=e?Buffer.byteLength(e):0;for(let f=0;f<r.length;++f)s+=4+Buffer.byteLength(r[f].prompt)+1;let a=this._packetRW.write.allocStart,c=this._packetRW.write.alloc(5+i+4+o+4+4+s);c[a]=Se.USERAUTH_INFO_REQUEST,B(c,i,++a),a+=4,t&&(c.utf8Write(t,a,i),a+=i),B(c,o,a),a+=4,e&&(c.utf8Write(e,a,o),a+=o),B(c,0,a),B(c,r.length,a+=4),a+=4;for(let f=0;f<r.length;++f){let l=r[f],u=Buffer.byteLength(l.prompt);B(c,u,a),a+=4,u&&(c.utf8Write(l.prompt,a,u),a+=u),c[a++]=l.echo?1:0}this._debug&&this._debug("Outbound: Sending USERAUTH_INFO_REQUEST"),we(this,this._packetRW.write.finalize(c))}},z0=/^SSH-(2\.0|1\.99)-([^ ]+)(?: (.*))?$/;function j0(n,t,e){let r,s;this._buffer?(r=Buffer.allocUnsafe(this._buffer.length+(e-t)),r.set(this._buffer,0),t===0?r.set(n,this._buffer.length):r.set(new Uint8Array(n.buffer,n.byteOffset+t,e-t),this._buffer.length),s=this._buffer.length,t=0):(r=n,s=0);let i=t,o=t,a=t,c=!1,f=0,l=0;for(;t<r.length;++t){let u=r[t];if(u===13){c=!0;continue}if(u===10){if(a>o&&a-o>4&&r[o]===83&&r[o+1]===83&&r[o+2]===72&&r[o+3]===45){let h=r.latin1Slice(i,a+1),g=o===i?h:h.slice(o-i),y=z0.exec(g);if(!y)throw new Error("Invalid identification string");let _={greeting:o===i?"":h.slice(0,o-i),identRaw:g,versions:{protocol:y[1],software:y[2]},comments:y[3]};return this._remoteIdentRaw=Buffer.from(g),this._debug&&this._debug(`Remote ident: ${bd(g)}`),this._compatFlags=Z0(_),this._buffer=void 0,this._decipher=new T0(0,M0.bind(this,{firstPacket:!0})),this._parse=X0,this._onHeader(_),this._destruct?(Sd(this),t+1-s):e}if(this._server)throw new Error("Greetings from clients not permitted");if(++l>G0)throw new Error("Max greeting lines exceeded");c=!1,o=t+1,f=0}else{if(c)throw new Error("Invalid header: expected newline");if(++f>=V0)throw new Error("Header line too long")}a=t}return this._buffer||(this._buffer=wd(r,i)),t-s}function X0(n,t,e){return this._decipher.decrypt(n,t,e)}function J0(n){if(this._onPacket(),n.length===0){this._debug&&this._debug("Inbound: Skipping empty packet payload");return}n=this._packetRW.read.read(n);let t=n[0];t===Se.USERAUTH_SUCCESS&&!this._server&&!this._authenticated&&(this._authenticated=!0,this._kex.negotiated.cs.compress==="zlib@openssh.com"&&(this._packetRW.write=new Cd(this)),this._kex.negotiated.sc.compress==="zlib@openssh.com"&&(this._packetRW.read=new Id));let e=$0[t];if(e===void 0){this._debug&&this._debug(`Inbound: Unsupported message type: ${t}`);return}return e(this,n)}function Z0(n){let t=n.versions.software,e=0;for(let r of L0)typeof r[0]=="string"?t===r[0]&&(e|=r[1]):r[0].test(t)&&(e|=r[1]);return e}function em(n){let t=Object.keys(n),e=Buffer.allocUnsafe(5*t.length+1),r=0;for(let s=0;s<t.length;++s){let i=t[s];if(i==="TTY_OP_END")continue;let o=Pa[i];if(o===void 0)continue;let a=n[i];typeof a=="number"&&isFinite(a)&&(e[r++]=o,e[r++]=a>>>24,e[r++]=a>>>16,e[r++]=a>>>8,e[r++]=a)}return e[r++]=Pa.TTY_OP_END,r<e.length?wd(e,0,r):e}function tm(n){let t="ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521rsa-sha2-512,rsa-sha2-256,ssh-rsa,ssh-dss";U0&&(t=`ssh-ed25519,${t}`);let e=Buffer.byteLength(t),r=n._packetRW.write.allocStart,s=n._packetRW.write.alloc(28+e);s[r]=Se.EXT_INFO,B(s,1,++r),B(s,15,r+=4),s.utf8Write("server-sig-algs",r+=4,15),B(s,e,r+=15),s.utf8Write(t,r+=4,e),n._debug&&n._debug("Outbound: Sending EXT_INFO"),we(n,n._packetRW.write.finalize(s))}kd.exports=Ta});var Ld=at(ki=>{"use strict";var Os=require("assert"),{inspect:nm}=require("util");function Bd(n){let t="",e=n.length,r=n[0]==="-"?1:0;for(;e>=r+4;e-=3)t=`_${n.slice(e-3,e)}${t}`;return`${n.slice(0,e)}${t}`}function Rd(n,t){if(Os(typeof t=="string","`thing` has to be of type string"),Array.isArray(n)){let e=n.length;return Os(e>0,"At least one expected value needs to be specified"),n=n.map(r=>String(r)),e>2?`one of ${t} ${n.slice(0,e-1).join(", ")}, or `+n[e-1]:e===2?`one of ${t} ${n[0]} or ${n[1]}`:`of ${t} ${n[0]}`}return`of ${t} ${String(n)}`}ki.ERR_INTERNAL_ASSERTION=class Pd extends Error{constructor(t){super(),Error.captureStackTrace(this,Pd);let e=`This is caused by either a bug in ssh2 or incorrect usage of ssh2 internals.
|
|
11
|
+
`)}else this._hostKeys=void 0;let u=t.offer;typeof u!="object"||u===null?u=this._server?wg:Sg:u.constructor!==Df&&(this._server?u.kex=u.kex.concat(["kex-strict-s-v00@openssh.com"]):u.kex=u.kex.concat(["ext-info-c","kex-strict-c-v00@openssh.com"]),u=new Df(u)),this._kex=void 0,this._strictMode=void 0,this._kexinit=void 0,this._offer=u,this._cipher=new _g(0,this._onWrite),this._decipher=void 0,this._skipNextInboundPacket=!1,this._packetRW={read:new kg,write:new Bg(this)},this._hostVerifier=!this._server&&typeof t.hostVerifier=="function"?t.hostVerifier:void 0,this._parse=Og,this._buffer=void 0,this._authsQueue=[],this._authenticated=!1,this._remoteIdentRaw=void 0;let h;if(typeof t.ident=="string")this._identRaw=Buffer.from(`SSH-2.0-${t.ident}`),h=Buffer.allocUnsafe(this._identRaw.length+2),h.set(this._identRaw,0),h[h.length-2]=13,h[h.length-1]=10;else if(Buffer.isBuffer(t.ident)){let g=Buffer.allocUnsafe(8+t.ident.length);g.latin1Write("SSH-2.0-",0,8),g.set(t.ident,8),this._identRaw=g,h=Buffer.allocUnsafe(g.length+2),h.set(g,0),h[h.length-2]=13,h[h.length-1]=10}else this._identRaw=Vf,h=Pg;this._compatFlags=0,this._debug&&(Eg?this._debug("Custom crypto binding available"):this._debug("Custom crypto binding not available")),this._debug&&this._debug(`Local ident: ${Ff(this._identRaw.toString())}`),this.start=()=>{this.start=void 0,l&&this._onWrite(l),this._onWrite(h)}}_destruct(t){this._packetRW.read.cleanup(),this._packetRW.write.cleanup(),this._cipher&&this._cipher.free(),this._decipher&&this._decipher.free(),(typeof t!="string"||t.length===0)&&(t="fatal error"),this.parse=()=>{throw new Error(`Instance unusable after ${t}`)},this._onWrite=()=>{throw new Error(`Instance unusable after ${t}`)},this._destruct=void 0}cleanup(){this._destruct&&this._destruct()}parse(t,e,r){for(;e<r;)e=this._parse(t,e,r)}disconnect(t){let r=this._packetRW.write.allocStartKEX,s=this._packetRW.write.alloc(13,!0),i=r+13;Ng.has(t)||(t=Hf.PROTOCOL_ERROR),s[r]=Se.DISCONNECT,B(s,t,++r),s.fill(0,r+=4,i),this._debug&&this._debug(`Outbound: Sending DISCONNECT (${t})`),we(this,this._packetRW.write.finalize(s,!0),!0)}ping(){let t=this._packetRW.write.allocStart,e=this._packetRW.write.alloc($f.length);e.set($f,t),this._debug&&this._debug("Outbound: Sending ping (GLOBAL_REQUEST: keepalive@openssh.com)"),we(this,this._packetRW.write.finalize(e))}rekey(){this._kexinit===void 0?(this._debug&&this._debug("Outbound: Initiated explicit rekey"),this._queue=[],Qf(this)):this._debug&&this._debug("Outbound: Ignoring rekey during handshake")}requestSuccess(t){let e=this._packetRW.write.allocStart,r;Buffer.isBuffer(t)?(r=this._packetRW.write.alloc(1+t.length),r[e]=Se.REQUEST_SUCCESS,r.set(t,++e)):(r=this._packetRW.write.alloc(1),r[e]=Se.REQUEST_SUCCESS),this._debug&&this._debug("Outbound: Sending REQUEST_SUCCESS"),we(this,this._packetRW.write.finalize(r))}requestFailure(){let t=this._packetRW.write.allocStart,e=this._packetRW.write.alloc(1);e[t]=Se.REQUEST_FAILURE,this._debug&&this._debug("Outbound: Sending REQUEST_FAILURE"),we(this,this._packetRW.write.finalize(e))}channelSuccess(t){let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(5);r[e]=Se.CHANNEL_SUCCESS,B(r,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_SUCCESS (r:${t})`),we(this,this._packetRW.write.finalize(r))}channelFailure(t){let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(5);r[e]=Se.CHANNEL_FAILURE,B(r,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_FAILURE (r:${t})`),we(this,this._packetRW.write.finalize(r))}channelEOF(t){let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(5);r[e]=Se.CHANNEL_EOF,B(r,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_EOF (r:${t})`),we(this,this._packetRW.write.finalize(r))}channelClose(t){let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(5);r[e]=Se.CHANNEL_CLOSE,B(r,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_CLOSE (r:${t})`),we(this,this._packetRW.write.finalize(r))}channelWindowAdjust(t,e){let r=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(9);s[r]=Se.CHANNEL_WINDOW_ADJUST,B(s,t,++r),B(s,e,r+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_WINDOW_ADJUST (r:${t}, ${e})`),we(this,this._packetRW.write.finalize(s))}channelData(t,e){let r=Buffer.isBuffer(e),s=r?e.length:Buffer.byteLength(e),i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(9+s);o[i]=Se.CHANNEL_DATA,B(o,t,++i),B(o,s,i+=4),r?o.set(e,i+=4):o.utf8Write(e,i+=4,s),this._debug&&this._debug(`Outbound: Sending CHANNEL_DATA (r:${t}, ${s})`),we(this,this._packetRW.write.finalize(o))}channelExtData(t,e,r){let s=Buffer.isBuffer(e),i=s?e.length:Buffer.byteLength(e),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(13+i);a[o]=Se.CHANNEL_EXTENDED_DATA,B(a,t,++o),B(a,r,o+=4),B(a,i,o+=4),s?a.set(e,o+=4):a.utf8Write(e,o+=4,i),this._debug&&this._debug(`Outbound: Sending CHANNEL_EXTENDED_DATA (r:${t})`),we(this,this._packetRW.write.finalize(a))}channelOpenConfirm(t,e,r,s){let i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(17);o[i]=Se.CHANNEL_OPEN_CONFIRMATION,B(o,t,++i),B(o,e,i+=4),B(o,r,i+=4),B(o,s,i+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN_CONFIRMATION (r:${t}, l:${e})`),we(this,this._packetRW.write.finalize(o))}channelOpenFail(t,e,r){typeof r!="string"&&(r="");let s=Buffer.byteLength(r),i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(13+s+4);o[i]=Se.CHANNEL_OPEN_FAILURE,B(o,t,++i),B(o,e,i+=4),B(o,s,i+=4),i+=4,s&&(o.utf8Write(r,i,s),i+=s),B(o,0,i),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN_FAILURE (r:${t})`),we(this,this._packetRW.write.finalize(o))}service(t){if(this._server)throw new Error("Client-only method called in server mode");let e=Buffer.byteLength(t),r=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(5+e);s[r]=Se.SERVICE_REQUEST,B(s,e,++r),s.utf8Write(t,r+=4,e),this._debug&&this._debug(`Outbound: Sending SERVICE_REQUEST (${t})`),we(this,this._packetRW.write.finalize(s))}authPassword(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let s=Buffer.byteLength(t),i=Buffer.byteLength(e),o=r?Buffer.byteLength(r):0,a=this._packetRW.write.allocStart,c=this._packetRW.write.alloc(5+s+4+14+4+8+1+4+i+(r?4+o:0));c[a]=Se.USERAUTH_REQUEST,B(c,s,++a),c.utf8Write(t,a+=4,s),B(c,14,a+=s),c.utf8Write("ssh-connection",a+=4,14),B(c,8,a+=14),c.utf8Write("password",a+=4,8),c[a+=8]=r?1:0,B(c,i,++a),Buffer.isBuffer(e)?_s(e,c,0,i,a+=4):c.utf8Write(e,a+=4,i),r?(B(c,o,a+=i),Buffer.isBuffer(r)?_s(r,c,0,o,a+=4):c.utf8Write(r,a+=4,o),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (changed password)")):this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (password)"),this._authsQueue.push("password"),we(this,this._packetRW.write.finalize(c))}authPK(t,e,r,s){if(this._server)throw new Error("Client-only method called in server mode");if(e=Of(e),e instanceof Error)throw new Error("Invalid key");let i=e.type;e=e.getPublicSSH(),typeof r=="function"&&(s=r,r=void 0),r||(r=i);let o=Buffer.byteLength(t),a=Buffer.byteLength(r),c=e.length,f=this._kex.sessionID,l=f.length,u=(s?4+l:0)+1+4+o+4+14+4+9+1+4+a+4+c,h,g;if(s?(h=Buffer.allocUnsafe(u),g=0,B(h,l,g),h.set(f,g+=4),g+=l):(h=this._packetRW.write.alloc(u),g=this._packetRW.write.allocStart),h[g]=Se.USERAUTH_REQUEST,B(h,o,++g),h.utf8Write(t,g+=4,o),B(h,14,g+=o),h.utf8Write("ssh-connection",g+=4,14),B(h,9,g+=14),h.utf8Write("publickey",g+=4,9),h[g+=9]=s?1:0,B(h,a,++g),h.utf8Write(r,g+=4,a),B(h,c,g+=a),h.set(e,g+=4),!s){this._authsQueue.push("publickey"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (publickey -- check)"),we(this,this._packetRW.write.finalize(h));return}s(h,y=>{if(y=Mf(y,i),y===!1)throw new Error("Error while converting handshake signature");let _=y.length;g=this._packetRW.write.allocStart,h=this._packetRW.write.alloc(5+o+4+14+4+9+1+4+a+4+c+4+4+a+4+_),h[g]=Se.USERAUTH_REQUEST,B(h,o,++g),h.utf8Write(t,g+=4,o),B(h,14,g+=o),h.utf8Write("ssh-connection",g+=4,14),B(h,9,g+=14),h.utf8Write("publickey",g+=4,9),h[g+=9]=1,B(h,a,++g),h.utf8Write(r,g+=4,a),B(h,c,g+=a),h.set(e,g+=4),B(h,4+a+4+_,g+=c),B(h,a,g+=4),h.utf8Write(r,g+=4,a),B(h,_,g+=a),h.set(y,g+=4),this._authsQueue.push("publickey"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (publickey)"),we(this,this._packetRW.write.finalize(h))})}authHostbased(t,e,r,s,i,o){if(this._server)throw new Error("Client-only method called in server mode");if(e=Of(e),e instanceof Error)throw new Error("Invalid key");let a=e.type;e=e.getPublicSSH(),typeof i=="function"&&(o=i,i=void 0),i||(i=a);let c=Buffer.byteLength(t),f=Buffer.byteLength(i),l=e.length,u=this._kex.sessionID,h=u.length,g=Buffer.byteLength(r),y=Buffer.byteLength(s),_=Buffer.allocUnsafe(4+h+1+4+c+4+14+4+9+4+f+4+l+4+g+4+y),b=0;B(_,h,b),_.set(u,b+=4),_[b+=h]=Se.USERAUTH_REQUEST,B(_,c,++b),_.utf8Write(t,b+=4,c),B(_,14,b+=c),_.utf8Write("ssh-connection",b+=4,14),B(_,9,b+=14),_.utf8Write("hostbased",b+=4,9),B(_,f,b+=9),_.utf8Write(i,b+=4,f),B(_,l,b+=f),_.set(e,b+=4),B(_,g,b+=l),_.utf8Write(r,b+=4,g),B(_,y,b+=g),_.utf8Write(s,b+=4,y),o(_,C=>{if(C=Mf(C,a),!C)throw new Error("Error while converting handshake signature");let L=C.length,F=_.length-h-4;b=this._packetRW.write.allocStart;let k=this._packetRW.write.alloc(F+4+4+f+4+L);_s(_,k,4+h,_.length,b),B(k,4+f+4+L,b+=F),B(k,f,b+=4),k.utf8Write(i,b+=4,f),B(k,L,b+=f),k.set(C,b+=4),this._authsQueue.push("hostbased"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (hostbased)"),we(this,this._packetRW.write.finalize(k))})}authKeyboard(t){if(this._server)throw new Error("Client-only method called in server mode");let e=Buffer.byteLength(t),r=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(5+e+4+14+4+20+4+4);s[r]=Se.USERAUTH_REQUEST,B(s,e,++r),s.utf8Write(t,r+=4,e),B(s,14,r+=e),s.utf8Write("ssh-connection",r+=4,14),B(s,20,r+=14),s.utf8Write("keyboard-interactive",r+=4,20),B(s,0,r+=20),B(s,0,r+=4),this._authsQueue.push("keyboard-interactive"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (keyboard-interactive)"),we(this,this._packetRW.write.finalize(s))}authNone(t){if(this._server)throw new Error("Client-only method called in server mode");let e=Buffer.byteLength(t),r=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(5+e+4+14+4+4);s[r]=Se.USERAUTH_REQUEST,B(s,e,++r),s.utf8Write(t,r+=4,e),B(s,14,r+=e),s.utf8Write("ssh-connection",r+=4,14),B(s,4,r+=14),s.utf8Write("none",r+=4,4),this._authsQueue.push("none"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (none)"),we(this,this._packetRW.write.finalize(s))}authInfoRes(t){if(this._server)throw new Error("Client-only method called in server mode");let e=0,r;if(t){r=new Array(t.length);for(let o=0;o<t.length;++o){let a=Buffer.byteLength(t[o]);r[o]=a,e+=4+a}}let s=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(5+e);if(i[s]=Se.USERAUTH_INFO_RESPONSE,t){B(i,t.length,++s),s+=4;for(let o=0;o<t.length;++o){let a=r[o];B(i,a,s),s+=4,a&&(i.utf8Write(t[o],s,a),s+=a)}}else B(i,0,++s);this._debug&&this._debug("Outbound: Sending USERAUTH_INFO_RESPONSE"),we(this,this._packetRW.write.finalize(i))}tcpipForward(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let s=Buffer.byteLength(t),i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(23+s+4);o[i]=Se.GLOBAL_REQUEST,B(o,13,++i),o.utf8Write("tcpip-forward",i+=4,13),o[i+=13]=r===void 0||r===!0?1:0,B(o,s,++i),o.utf8Write(t,i+=4,s),B(o,e,i+=s),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (tcpip-forward)"),we(this,this._packetRW.write.finalize(o))}cancelTcpipForward(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let s=Buffer.byteLength(t),i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(30+s+4);o[i]=Se.GLOBAL_REQUEST,B(o,20,++i),o.utf8Write("cancel-tcpip-forward",i+=4,20),o[i+=20]=r===void 0||r===!0?1:0,B(o,s,++i),o.utf8Write(t,i+=4,s),B(o,e,i+=s),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (cancel-tcpip-forward)"),we(this,this._packetRW.write.finalize(o))}openssh_streamLocalForward(t,e){if(this._server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),s=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(41+r);i[s]=Se.GLOBAL_REQUEST,B(i,31,++s),i.utf8Write("streamlocal-forward@openssh.com",s+=4,31),i[s+=31]=e===void 0||e===!0?1:0,B(i,r,++s),i.utf8Write(t,s+=4,r),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (streamlocal-forward@openssh.com)"),we(this,this._packetRW.write.finalize(i))}openssh_cancelStreamLocalForward(t,e){if(this._server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),s=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(48+r);i[s]=Se.GLOBAL_REQUEST,B(i,38,++s),i.utf8Write("cancel-streamlocal-forward@openssh.com",s+=4,38),i[s+=38]=e===void 0||e===!0?1:0,B(i,r,++s),i.utf8Write(t,s+=4,r),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (cancel-streamlocal-forward@openssh.com)"),we(this,this._packetRW.write.finalize(i))}directTcpip(t,e,r,s){if(this._server)throw new Error("Client-only method called in server mode");let i=Buffer.byteLength(s.srcIP),o=Buffer.byteLength(s.dstIP),a=this._packetRW.write.allocStart,c=this._packetRW.write.alloc(33+i+4+4+o+4);c[a]=Se.CHANNEL_OPEN,B(c,12,++a),c.utf8Write("direct-tcpip",a+=4,12),B(c,t,a+=12),B(c,e,a+=4),B(c,r,a+=4),B(c,o,a+=4),c.utf8Write(s.dstIP,a+=4,o),B(c,s.dstPort,a+=o),B(c,i,a+=4),c.utf8Write(s.srcIP,a+=4,i),B(c,s.srcPort,a+=i),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, direct-tcpip)`),we(this,this._packetRW.write.finalize(c))}openssh_directStreamLocal(t,e,r,s){if(this._server)throw new Error("Client-only method called in server mode");let i=Buffer.byteLength(s.socketPath),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(51+i+4+4);a[o]=Se.CHANNEL_OPEN,B(a,30,++o),a.utf8Write("direct-streamlocal@openssh.com",o+=4,30),B(a,t,o+=30),B(a,e,o+=4),B(a,r,o+=4),B(a,i,o+=4),a.utf8Write(s.socketPath,o+=4,i),vg(a,0,o+=i,o+8),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, direct-streamlocal@openssh.com)`),we(this,this._packetRW.write.finalize(a))}openssh_noMoreSessions(t){if(this._server)throw new Error("Client-only method called in server mode");let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(34);r[e]=Se.GLOBAL_REQUEST,B(r,28,++e),r.utf8Write("no-more-sessions@openssh.com",e+=4,28),r[e+=28]=t===void 0||t===!0?1:0,this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (no-more-sessions@openssh.com)"),we(this,this._packetRW.write.finalize(r))}session(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let s=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(24);i[s]=Se.CHANNEL_OPEN,B(i,7,++s),i.utf8Write("session",s+=4,7),B(i,t,s+=7),B(i,e,s+=4),B(i,r,s+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, session)`),we(this,this._packetRW.write.finalize(i))}windowChange(t,e,r,s,i){if(this._server)throw new Error("Client-only method called in server mode");let o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(39);a[o]=Se.CHANNEL_REQUEST,B(a,t,++o),B(a,13,o+=4),a.utf8Write("window-change",o+=4,13),a[o+=13]=0,B(a,r,++o),B(a,e,o+=4),B(a,i,o+=4),B(a,s,o+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, window-change)`),we(this,this._packetRW.write.finalize(a))}pty(t,e,r,s,i,o,a,c){if(this._server)throw new Error("Client-only method called in server mode");(!o||!o.length)&&(o="vt100"),a&&!Buffer.isBuffer(a)&&!Array.isArray(a)&&typeof a=="object"&&a!==null&&(a=Hg(a)),(!a||!a.length)&&(a=Ug);let f=o.length,l=a.length,u=this._packetRW.write.allocStart,h=this._packetRW.write.alloc(21+f+4+4+4+4+4+l);if(h[u]=Se.CHANNEL_REQUEST,B(h,t,++u),B(h,7,u+=4),h.utf8Write("pty-req",u+=4,7),h[u+=7]=c===void 0||c===!0?1:0,B(h,f,++u),h.utf8Write(o,u+=4,f),B(h,r,u+=f),B(h,e,u+=4),B(h,i,u+=4),B(h,s,u+=4),B(h,l,u+=4),u+=4,Array.isArray(a))for(let g=0;g<l;++g)h[u++]=a[g];else Buffer.isBuffer(a)&&h.set(a,u);this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, pty-req)`),we(this,this._packetRW.write.finalize(h))}shell(t,e){if(this._server)throw new Error("Client-only method called in server mode");let r=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(15);s[r]=Se.CHANNEL_REQUEST,B(s,t,++r),B(s,5,r+=4),s.utf8Write("shell",r+=4,5),s[r+=5]=e===void 0||e===!0?1:0,this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, shell)`),we(this,this._packetRW.write.finalize(s))}exec(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let s=Buffer.isBuffer(e),i=s?e.length:Buffer.byteLength(e),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(18+i);a[o]=Se.CHANNEL_REQUEST,B(a,t,++o),B(a,4,o+=4),a.utf8Write("exec",o+=4,4),a[o+=4]=r===void 0||r===!0?1:0,B(a,i,++o),s?a.set(e,o+=4):a.utf8Write(e,o+=4,i),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, exec: ${e})`),we(this,this._packetRW.write.finalize(a))}signal(t,e){if(this._server)throw new Error("Client-only method called in server mode");let r=e;if(e=e.toUpperCase(),e.slice(0,3)==="SIG"&&(e=e.slice(3)),Uf[e]!==1)throw new Error(`Invalid signal: ${r}`);let s=e.length,i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(20+s);o[i]=Se.CHANNEL_REQUEST,B(o,t,++i),B(o,6,i+=4),o.utf8Write("signal",i+=4,6),o[i+=6]=0,B(o,s,++i),o.utf8Write(e,i+=4,s),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, signal: ${e})`),we(this,this._packetRW.write.finalize(o))}env(t,e,r,s){if(this._server)throw new Error("Client-only method called in server mode");let i=Buffer.byteLength(e),o=Buffer.isBuffer(r),a=o?r.length:Buffer.byteLength(r),c=this._packetRW.write.allocStart,f=this._packetRW.write.alloc(17+i+4+a);f[c]=Se.CHANNEL_REQUEST,B(f,t,++c),B(f,3,c+=4),f.utf8Write("env",c+=4,3),f[c+=3]=s===void 0||s===!0?1:0,B(f,i,++c),f.utf8Write(e,c+=4,i),B(f,a,c+=i),o?f.set(r,c+=4):f.utf8Write(r,c+=4,a),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, env: ${e}=${r})`),we(this,this._packetRW.write.finalize(f))}x11Forward(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let s=e.protocol,i=e.cookie,o=Buffer.isBuffer(s),a=o?s.length:Buffer.byteLength(s),c=Buffer.isBuffer(i),f=c?i.length:Buffer.byteLength(i),l=this._packetRW.write.allocStart,u=this._packetRW.write.alloc(22+a+4+f+4);u[l]=Se.CHANNEL_REQUEST,B(u,t,++l),B(u,7,l+=4),u.utf8Write("x11-req",l+=4,7),u[l+=7]=r===void 0||r===!0?1:0,u[++l]=e.single?1:0,B(u,a,++l),o?u.set(s,l+=4):u.utf8Write(s,l+=4,a),B(u,f,l+=a),c?u.set(i,l+=4):u.latin1Write(i,l+=4,f),B(u,e.screen||0,l+=f),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, x11-req)`),we(this,this._packetRW.write.finalize(u))}subsystem(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let s=Buffer.byteLength(e),i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(23+s);o[i]=Se.CHANNEL_REQUEST,B(o,t,++i),B(o,9,i+=4),o.utf8Write("subsystem",i+=4,9),o[i+=9]=r===void 0||r===!0?1:0,B(o,s,++i),o.utf8Write(e,i+=4,s),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, subsystem: ${e})`),we(this,this._packetRW.write.finalize(o))}openssh_agentForward(t,e){if(this._server)throw new Error("Client-only method called in server mode");let r=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(36);s[r]=Se.CHANNEL_REQUEST,B(s,t,++r),B(s,26,r+=4),s.utf8Write("auth-agent-req@openssh.com",r+=4,26),s[r+=26]=e===void 0||e===!0?1:0,this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, auth-agent-req@openssh.com)`),we(this,this._packetRW.write.finalize(s))}openssh_hostKeysProve(t){if(this._server)throw new Error("Client-only method called in server mode");let e=0,r=[];for(let o of t){let a=o.getPublicSSH();e+=4+a.length,r.push(a)}let s=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(35+e);i[s]=Se.GLOBAL_REQUEST,B(i,29,++s),i.utf8Write("hostkeys-prove-00@openssh.com",s+=4,29),i[s+=29]=1,++s;for(let o of r)B(i,o.length,s),_s(o,i,0,o.length,s+=4),s+=o.length;this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (hostkeys-prove-00@openssh.com)"),we(this,this._packetRW.write.finalize(i))}serviceAccept(t){if(!this._server)throw new Error("Server-only method called in client mode");let e=Buffer.byteLength(t),r=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(5+e);if(s[r]=Se.SERVICE_ACCEPT,B(s,e,++r),s.utf8Write(t,r+=4,e),this._debug&&this._debug(`Outbound: Sending SERVICE_ACCEPT (${t})`),we(this,this._packetRW.write.finalize(s)),this._server&&this._banner&&t==="ssh-userauth"){let i=this._banner;this._banner=void 0;let o=Buffer.byteLength(i);r=this._packetRW.write.allocStart;let a=this._packetRW.write.alloc(5+o+4);a[r]=Se.USERAUTH_BANNER,B(a,o,++r),a.utf8Write(i,r+=4,o),B(a,0,r+=o),this._debug&&this._debug("Outbound: Sending USERAUTH_BANNER"),we(this,this._packetRW.write.finalize(a))}}forwardedTcpip(t,e,r,s){if(!this._server)throw new Error("Server-only method called in client mode");let i=Buffer.byteLength(s.boundAddr),o=Buffer.byteLength(s.remoteAddr),a=this._packetRW.write.allocStart,c=this._packetRW.write.alloc(36+i+4+4+o+4);c[a]=Se.CHANNEL_OPEN,B(c,15,++a),c.utf8Write("forwarded-tcpip",a+=4,15),B(c,t,a+=15),B(c,e,a+=4),B(c,r,a+=4),B(c,i,a+=4),c.utf8Write(s.boundAddr,a+=4,i),B(c,s.boundPort,a+=i),B(c,o,a+=4),c.utf8Write(s.remoteAddr,a+=4,o),B(c,s.remotePort,a+=o),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, forwarded-tcpip)`),we(this,this._packetRW.write.finalize(c))}x11(t,e,r,s){if(!this._server)throw new Error("Server-only method called in client mode");let i=Buffer.byteLength(s.originAddr),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(24+i+4);a[o]=Se.CHANNEL_OPEN,B(a,3,++o),a.utf8Write("x11",o+=4,3),B(a,t,o+=3),B(a,e,o+=4),B(a,r,o+=4),B(a,i,o+=4),a.utf8Write(s.originAddr,o+=4,i),B(a,s.originPort,o+=i),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, x11)`),we(this,this._packetRW.write.finalize(a))}openssh_authAgent(t,e,r){if(!this._server)throw new Error("Server-only method called in client mode");let s=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(39);i[s]=Se.CHANNEL_OPEN,B(i,22,++s),i.utf8Write("auth-agent@openssh.com",s+=4,22),B(i,t,s+=22),B(i,e,s+=4),B(i,r,s+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, auth-agent@openssh.com)`),we(this,this._packetRW.write.finalize(i))}openssh_forwardedStreamLocal(t,e,r,s){if(!this._server)throw new Error("Server-only method called in client mode");let i=Buffer.byteLength(s.socketPath),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(54+i+4);a[o]=Se.CHANNEL_OPEN,B(a,33,++o),a.utf8Write("forwarded-streamlocal@openssh.com",o+=4,33),B(a,t,o+=33),B(a,e,o+=4),B(a,r,o+=4),B(a,i,o+=4),a.utf8Write(s.socketPath,o+=4,i),B(a,0,o+=i),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, forwarded-streamlocal@openssh.com)`),we(this,this._packetRW.write.finalize(a))}exitStatus(t,e){if(!this._server)throw new Error("Server-only method called in client mode");let r=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(25);s[r]=Se.CHANNEL_REQUEST,B(s,t,++r),B(s,11,r+=4),s.utf8Write("exit-status",r+=4,11),s[r+=11]=0,B(s,e,++r),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, exit-status: ${e})`),we(this,this._packetRW.write.finalize(s))}exitSignal(t,e,r,s){if(!this._server)throw new Error("Server-only method called in client mode");let i=e;if(typeof i!="string"||!i)throw new Error(`Invalid signal: ${i}`);let o=e.toUpperCase();if(o.slice(0,3)==="SIG"&&(o=o.slice(3)),Uf[o]!==1)throw new Error(`Invalid signal: ${i}`);let a=Buffer.byteLength(o),c=s?Buffer.byteLength(s):0,f=this._packetRW.write.allocStart,l=this._packetRW.write.alloc(25+a+1+4+c+4);l[f]=Se.CHANNEL_REQUEST,B(l,t,++f),B(l,11,f+=4),l.utf8Write("exit-signal",f+=4,11),l[f+=11]=0,B(l,a,++f),l.utf8Write(o,f+=4,a),l[f+=a]=r?1:0,B(l,c,++f),f+=4,c&&(l.utf8Write(s,f,c),f+=c),B(l,0,f),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, exit-signal: ${e})`),we(this,this._packetRW.write.finalize(l))}authFailure(t,e){if(!this._server)throw new Error("Server-only method called in client mode");if(this._authsQueue.length===0)throw new Error("No auth in progress");let r;if(typeof t=="boolean"&&(e=t,t=void 0),t){r=[];for(let a=0;a<t.length;++a)t[a].toLowerCase()!=="none"&&r.push(t[a]);r=r.join(",")}else r="";let s=r.length,i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(5+s+1);o[i]=Se.USERAUTH_FAILURE,B(o,s,++i),o.utf8Write(r,i+=4,s),o[i+=s]=e===!0?1:0,this._authsQueue.shift(),this._debug&&this._debug("Outbound: Sending USERAUTH_FAILURE"),we(this,this._packetRW.write.finalize(o))}authSuccess(){if(!this._server)throw new Error("Server-only method called in client mode");if(this._authsQueue.length===0)throw new Error("No auth in progress");let t=this._packetRW.write.allocStart,e=this._packetRW.write.alloc(1);e[t]=Se.USERAUTH_SUCCESS,this._authsQueue.shift(),this._authenticated=!0,this._debug&&this._debug("Outbound: Sending USERAUTH_SUCCESS"),we(this,this._packetRW.write.finalize(e)),this._kex.negotiated.cs.compress==="zlib@openssh.com"&&(this._packetRW.read=new qf),this._kex.negotiated.sc.compress==="zlib@openssh.com"&&(this._packetRW.write=new Kf(this))}authPKOK(t,e){if(!this._server)throw new Error("Server-only method called in client mode");if(this._authsQueue.length===0||this._authsQueue[0]!=="publickey")throw new Error('"publickey" auth not in progress');let r=Buffer.byteLength(t),s=e.length,i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(5+r+4+s);o[i]=Se.USERAUTH_PK_OK,B(o,r,++i),o.utf8Write(t,i+=4,r),B(o,s,i+=r),o.set(e,i+=4),this._authsQueue.shift(),this._debug&&this._debug("Outbound: Sending USERAUTH_PK_OK"),we(this,this._packetRW.write.finalize(o))}authPasswdChg(t){if(!this._server)throw new Error("Server-only method called in client mode");let e=Buffer.byteLength(t),r=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(5+e+4);s[r]=Se.USERAUTH_PASSWD_CHANGEREQ,B(s,e,++r),s.utf8Write(t,r+=4,e),B(s,0,r+=e),this._debug&&this._debug("Outbound: Sending USERAUTH_PASSWD_CHANGEREQ"),we(this,this._packetRW.write.finalize(s))}authInfoReq(t,e,r){if(!this._server)throw new Error("Server-only method called in client mode");let s=0,i=t?Buffer.byteLength(t):0,o=e?Buffer.byteLength(e):0;for(let f=0;f<r.length;++f)s+=4+Buffer.byteLength(r[f].prompt)+1;let a=this._packetRW.write.allocStart,c=this._packetRW.write.alloc(5+i+4+o+4+4+s);c[a]=Se.USERAUTH_INFO_REQUEST,B(c,i,++a),a+=4,t&&(c.utf8Write(t,a,i),a+=i),B(c,o,a),a+=4,e&&(c.utf8Write(e,a,o),a+=o),B(c,0,a),B(c,r.length,a+=4),a+=4;for(let f=0;f<r.length;++f){let l=r[f],u=Buffer.byteLength(l.prompt);B(c,u,a),a+=4,u&&(c.utf8Write(l.prompt,a,u),a+=u),c[a++]=l.echo?1:0}this._debug&&this._debug("Outbound: Sending USERAUTH_INFO_REQUEST"),we(this,this._packetRW.write.finalize(c))}},Dg=/^SSH-(2\.0|1\.99)-([^ ]+)(?: (.*))?$/;function Og(n,t,e){let r,s;this._buffer?(r=Buffer.allocUnsafe(this._buffer.length+(e-t)),r.set(this._buffer,0),t===0?r.set(n,this._buffer.length):r.set(new Uint8Array(n.buffer,n.byteOffset+t,e-t),this._buffer.length),s=this._buffer.length,t=0):(r=n,s=0);let i=t,o=t,a=t,c=!1,f=0,l=0;for(;t<r.length;++t){let u=r[t];if(u===13){c=!0;continue}if(u===10){if(a>o&&a-o>4&&r[o]===83&&r[o+1]===83&&r[o+2]===72&&r[o+3]===45){let h=r.latin1Slice(i,a+1),g=o===i?h:h.slice(o-i),y=Dg.exec(g);if(!y)throw new Error("Invalid identification string");let _={greeting:o===i?"":h.slice(0,o-i),identRaw:g,versions:{protocol:y[1],software:y[2]},comments:y[3]};return this._remoteIdentRaw=Buffer.from(g),this._debug&&this._debug(`Remote ident: ${Ff(g)}`),this._compatFlags=Fg(_),this._buffer=void 0,this._decipher=new yg(0,Ig.bind(this,{firstPacket:!0})),this._parse=Mg,this._onHeader(_),this._destruct?(Qf(this),t+1-s):e}if(this._server)throw new Error("Greetings from clients not permitted");if(++l>Lg)throw new Error("Max greeting lines exceeded");c=!1,o=t+1,f=0}else{if(c)throw new Error("Invalid header: expected newline");if(++f>=Tg)throw new Error("Header line too long")}a=t}return this._buffer||(this._buffer=Wf(r,i)),t-s}function Mg(n,t,e){return this._decipher.decrypt(n,t,e)}function $g(n){if(this._onPacket(),n.length===0){this._debug&&this._debug("Inbound: Skipping empty packet payload");return}n=this._packetRW.read.read(n);let t=n[0];t===Se.USERAUTH_SUCCESS&&!this._server&&!this._authenticated&&(this._authenticated=!0,this._kex.negotiated.cs.compress==="zlib@openssh.com"&&(this._packetRW.write=new Kf(this)),this._kex.negotiated.sc.compress==="zlib@openssh.com"&&(this._packetRW.read=new qf));let e=Cg[t];if(e===void 0){this._debug&&this._debug(`Inbound: Unsupported message type: ${t}`);return}return e(this,n)}function Fg(n){let t=n.versions.software,e=0;for(let r of bg)typeof r[0]=="string"?t===r[0]&&(e|=r[1]):r[0].test(t)&&(e|=r[1]);return e}function Hg(n){let t=Object.keys(n),e=Buffer.allocUnsafe(5*t.length+1),r=0;for(let s=0;s<t.length;++s){let i=t[s];if(i==="TTY_OP_END")continue;let o=ua[i];if(o===void 0)continue;let a=n[i];typeof a=="number"&&isFinite(a)&&(e[r++]=o,e[r++]=a>>>24,e[r++]=a>>>16,e[r++]=a>>>8,e[r++]=a)}return e[r++]=ua.TTY_OP_END,r<e.length?Wf(e,0,r):e}function Qg(n){let t="ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521rsa-sha2-512,rsa-sha2-256,ssh-rsa,ssh-dss";xg&&(t=`ssh-ed25519,${t}`);let e=Buffer.byteLength(t),r=n._packetRW.write.allocStart,s=n._packetRW.write.alloc(28+e);s[r]=Se.EXT_INFO,B(s,1,++r),B(s,15,r+=4),s.utf8Write("server-sig-algs",r+=4,15),B(s,e,r+=15),s.utf8Write(t,r+=4,e),n._debug&&n._debug("Outbound: Sending EXT_INFO"),we(n,n._packetRW.write.finalize(s))}Gf.exports=da});var Zf=at(yi=>{"use strict";var ys=require("assert"),{inspect:Wg}=require("util");function Yf(n){let t="",e=n.length,r=n[0]==="-"?1:0;for(;e>=r+4;e-=3)t=`_${n.slice(e-3,e)}${t}`;return`${n.slice(0,e)}${t}`}function zf(n,t){if(ys(typeof t=="string","`thing` has to be of type string"),Array.isArray(n)){let e=n.length;return ys(e>0,"At least one expected value needs to be specified"),n=n.map(r=>String(r)),e>2?`one of ${t} ${n.slice(0,e-1).join(", ")}, or `+n[e-1]:e===2?`one of ${t} ${n[0]} or ${n[1]}`:`of ${t} ${n[0]}`}return`of ${t} ${String(n)}`}yi.ERR_INTERNAL_ASSERTION=class Xf extends Error{constructor(t){super(),Error.captureStackTrace(this,Xf);let e=`This is caused by either a bug in ssh2 or incorrect usage of ssh2 internals.
|
|
12
12
|
Please open an issue with this stack trace at https://github.com/mscdex/ssh2/issues
|
|
13
13
|
`;this.message=t===void 0?e:`${t}
|
|
14
|
-
${e}`}};var rm=2**32,Nd=(()=>{try{return new Function("return 2n ** 32n")()}catch{}})();ki.ERR_OUT_OF_RANGE=class Td extends RangeError{constructor(t,e,r,s){super(),Error.captureStackTrace(this,Td),Os(e,'Missing "range" argument');let i=s?t:`The value of "${t}" is out of range.`,o;Number.isInteger(r)&&Math.abs(r)>rm?o=Bd(String(r)):typeof r=="bigint"?(o=String(r),(r>Nd||r<-Nd)&&(o=Bd(o)),o+="n"):o=nm(r),i+=` It must be ${e}. Received ${o}`,this.message=i}};var Ms=class n extends TypeError{constructor(t,e,r){super(),Error.captureStackTrace(this,n),Os(typeof t=="string","'name' must be a string");let s;typeof e=="string"&&e.startsWith("not ")?(s="must not be",e=e.replace(/^not /,"")):s="must be";let i;if(t.endsWith(" argument"))i=`The ${t} ${s} ${Rd(e,"type")}`;else{let o=t.includes(".")?"property":"argument";i=`The "${t}" ${o} ${s} ${Rd(e,"type")}`}i+=`. Received type ${typeof r}`,this.message=i}};ki.ERR_INVALID_ARG_TYPE=Ms;ki.validateNumber=function(t,e){if(typeof t!="number")throw new Ms(e,"number",t)}});var Bi=at((Xx,Gd)=>{"use strict";var im=require("events"),jn=require("fs"),{constants:Zt}=jn,{Readable:Fd,Writable:Wa}=require("stream"),{inherits:Hd,types:{isDate:Oa}}=require("util"),sm=Buffer[Symbol.species],{bufferCopy:zn,bufferSlice:Kr,makeBufferParser:om,writeUInt32BE:q}=hn(),On={SIZE:1,UIDGID:2,PERMISSIONS:4,ACMODTIME:8,EXTENDED:2147483648},Ne=Buffer.alloc(28),et={OK:0,EOF:1,NO_SUCH_FILE:2,PERMISSION_DENIED:3,FAILURE:4,BAD_MESSAGE:5,NO_CONNECTION:6,CONNECTION_LOST:7,OP_UNSUPPORTED:8},am=new Map(Object.values(et).map(n=>[n,1])),cm={[et.OK]:"No error",[et.EOF]:"End of file",[et.NO_SUCH_FILE]:"No such file or directory",[et.PERMISSION_DENIED]:"Permission denied",[et.FAILURE]:"Failure",[et.BAD_MESSAGE]:"Bad message",[et.NO_CONNECTION]:"No connection",[et.CONNECTION_LOST]:"Connection lost",[et.OP_UNSUPPORTED]:"Operation unsupported"},ke={INIT:1,OPEN:3,CLOSE:4,READ:5,WRITE:6,LSTAT:7,FSTAT:8,SETSTAT:9,FSETSTAT:10,OPENDIR:11,READDIR:12,REMOVE:13,MKDIR:14,RMDIR:15,REALPATH:16,STAT:17,RENAME:18,READLINK:19,SYMLINK:20,EXTENDED:200},en={VERSION:2,STATUS:101,HANDLE:102,DATA:103,NAME:104,ATTRS:105,EXTENDED:201},Ie={READ:1,WRITE:2,APPEND:4,CREAT:8,TRUNC:16,EXCL:32},Ud=2*1024,ft=2**32-1,fm=Buffer.from([0,0,0,5,ke.INIT,0,0,0,3]),lm=Buffer.from([0,0,0,5,en.VERSION,0,0,0,3]),um=/^SSH-2.0-(?:OpenSSH|dropbear)/,Ua=256*1024,M=om(),dm={readable:!1,writable:!1,push:n=>{},once:()=>{},on:()=>{},emit:()=>{},end:()=>{}};function Qd(){}var Ma=class extends im{constructor(t,e,r){super(),(typeof r!="object"||!r)&&(r={});let s=t._protocol._remoteIdentRaw;this.server=!!r.server,this._debug=typeof r.debug=="function"?r.debug:void 0,this._isOpenSSH=s&&um.test(s),this._version=-1,this._extensions={},this._biOpt=r.biOpt,this._pktLenBytes=0,this._pktLen=0,this._pktPos=0,this._pktType=0,this._pktData=void 0,this._writeReqid=-1,this._requests={},this._maxInPktLen=Ua,this._maxOutPktLen=34e3,this._maxReadLen=(this._isOpenSSH?Ua:34e3)-Ud,this._maxWriteLen=(this._isOpenSSH?Ua:34e3)-Ud,this.maxOpenHandles=void 0,this._client=t,this._protocol=t._protocol,this._callbacks=[],this._hasX11=!1,this._exit={code:void 0,signal:void 0,dump:void 0,desc:void 0},this._waitWindow=!1,this._chunkcb=void 0,this._buffer=[],this.type=e.type,this.subtype=void 0,this.incoming=e.incoming,this.outgoing=e.outgoing,this.stderr=dm,this.readable=!0}push(t){if(t===null){if(Vd(this),!this.readable)return;this.readable=!1,this.emit("end");return}let e=0;for(;e<t.length;){if(this._pktLenBytes<4){let o=Math.min(4-this._pktLenBytes,t.length-e);for(this._pktLenBytes+=o;o--;)this._pktLen=(this._pktLen<<8)+t[e++];if(this._pktLenBytes<4)return;if(this._pktLen===0)return st(this,"Invalid packet length");if(this._pktLen>this._maxInPktLen){let a=this._maxInPktLen;return st(this,`Packet length ${this._pktLen} exceeds max length of ${a}`)}if(e>=t.length)return}if(this._pktPos<this._pktLen){let o=Math.min(this._pktLen-this._pktPos,t.length-e);if(e!==0||o!==t.length?o===this._pktLen?this._pkt=new sm(t.buffer,t.byteOffset+e,o):(this._pkt||(this._pkt=Buffer.allocUnsafe(this._pktLen)),this._pkt.set(new Uint8Array(t.buffer,t.byteOffset+e,o),this._pktPos)):o===this._pktLen?this._pkt=t:(this._pkt||(this._pkt=Buffer.allocUnsafe(this._pktLen)),this._pkt.set(t,this._pktPos)),e+=o,this._pktPos+=o,this._pktPos<this._pktLen)return}let r=this._pkt[0],s=this._pkt;this._pktLen=0,this._pktLenBytes=0,this._pkt=void 0,this._pktPos=0;let i=this.server?Am[r]:mm[r];if(!i)return st(this,`Unknown packet type ${r}`);if(this._version===-1){if(this.server){if(r!==ke.INIT)return st(this,`Expected INIT packet, got ${r}`)}else if(r!==en.VERSION)return st(this,`Expected VERSION packet, got ${r}`)}if(i(this,s)===!1)return}}end(){this.destroy()}destroy(){(this.outgoing.state==="open"||this.outgoing.state==="eof")&&(this.outgoing.state="closing",this._protocol.channelClose(this.outgoing.id))}_init(){this._init=Qd,this.server||Xe(this,fm)}createReadStream(t,e){if(this.server)throw new Error("Client-only method called in server mode");return new Mn(this,t,e)}createWriteStream(t,e){if(this.server)throw new Error("Client-only method called in server mode");return new un(this,t,e)}open(t,e,r,s){if(this.server)throw new Error("Client-only method called in server mode");typeof r=="function"&&(s=r,r=void 0);let i=typeof e=="number"?e:qd(e);if(i===null)throw new Error(`Unknown flags string: ${e}`);let o=0,a=0;(typeof r=="string"||typeof r=="number")&&(r={mode:r}),typeof r=="object"&&r!==null&&(r=hr(r),o=r.flags,a=r.nb);let c=Buffer.byteLength(t),f=9,l=Buffer.allocUnsafe(13+c+4+4+a);q(l,l.length-4,0),l[4]=ke.OPEN;let u=this._writeReqid=this._writeReqid+1&ft;q(l,u,5),q(l,c,f),l.utf8Write(t,f+=4,c),q(l,i,f+=c),q(l,o,f+=4),a&&(f+=4,a===Ne.length?l.set(Ne,f):zn(Ne,l,0,a,f),f+=a),this._requests[u]={cb:s};let h=Xe(this,l);this._debug&&this._debug(`SFTP: Outbound: ${h?"Buffered":"Sending"} OPEN`)}close(t,e){if(this.server)throw new Error("Client-only method called in server mode");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");let r=t.length,s=9,i=Buffer.allocUnsafe(13+r);q(i,i.length-4,0),i[4]=ke.CLOSE;let o=this._writeReqid=this._writeReqid+1&ft;q(i,o,5),q(i,r,s),i.set(t,s+=4),this._requests[o]={cb:e};let a=Xe(this,i);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} CLOSE`)}read(t,e,r,s,i,o){if(this.server)throw new Error("Client-only method called in server mode");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");if(!Buffer.isBuffer(e))throw new Error("buffer is not a Buffer");if(r>=e.length)throw new Error("offset is out of bounds");if(r+s>e.length)throw new Error("length extends beyond buffer");if(i===null)throw new Error("null position currently unsupported");Wd(this,t,e,r,s,i,o)}readData(t,e,r,s,i,o){this.read(t,e,r,s,i,o)}write(t,e,r,s,i,o){if(this.server)throw new Error("Client-only method called in server mode");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");if(!Buffer.isBuffer(e))throw new Error("buffer is not a Buffer");if(r>e.length)throw new Error("offset is out of bounds");if(r+s>e.length)throw new Error("length extends beyond buffer");if(i===null)throw new Error("null position currently unsupported");if(!s){o&&process.nextTick(o,void 0,0);return}let a=this._maxWriteLen,c=Math.max(s-a,0),f=i;c&&(s=a);let l=t.length,u=9,h=Buffer.allocUnsafe(13+l+8+4+s);q(h,h.length-4,0),h[4]=ke.WRITE;let g=this._writeReqid=this._writeReqid+1&ft;q(h,g,5),q(h,l,u),h.set(t,u+=4),u+=l;for(let _=7;_>=0;--_)h[u+_]=i&255,i/=256;q(h,s,u+=8),zn(e,h,r,r+s,u+=4),this._requests[g]={cb:_=>{_?typeof o=="function"&&o(_):c?this.write(t,e,r+s,c,f+s,o):typeof o=="function"&&o(void 0,r+s)}};let y=Xe(this,h);if(this._debug){let _=y?"Sent":"Buffered";this._debug(`SFTP: Outbound: ${_} WRITE (id:${g})`)}}writeData(t,e,r,s,i,o){this.write(t,e,r,s,i,o)}fastGet(t,e,r,s){if(this.server)throw new Error("Client-only method called in server mode");Dd(this,jn,t,e,r,s)}fastPut(t,e,r,s){if(this.server)throw new Error("Client-only method called in server mode");Dd(jn,this,t,e,r,s)}readFile(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");let s;if(typeof r=="function"?s=r:typeof e=="function"&&(s=e,e=void 0),typeof e=="string")e={encoding:e,flag:"r"};else if(!e)e={encoding:null,flag:"r"};else if(typeof e!="object")throw new TypeError("Bad arguments");let i=e.encoding;if(i&&!Buffer.isEncoding(i))throw new Error(`Unknown encoding: ${i}`);let o,a,c,f=0,l,u=0,h=e.flag||"r",g=()=>{o===0?(a=Buffer.allocUnsafe(8192),this.read(l,a,0,8192,u,y)):this.read(l,a,f,o-f,u,y)},y=(b,C)=>{let L;if(b){if(L=b.code===et.EOF,!L)return this.close(l,()=>s&&s(b))}else L=!1;if(L||o===0&&C===0)return _();u+=C,f+=C,o!==0?f===o?_():g():(c.push(Kr(a,0,C)),g())};y._wantEOFError=!0;let _=()=>{this.close(l,b=>(o===0?a=Buffer.concat(c,f):f<o&&(a=Kr(a,0,f)),i&&(a=a.toString(i)),s&&s(b,a)))};this.open(t,h,438,(b,C)=>{if(b)return s&&s(b);l=C;let L=(F,k)=>{if(F){this.stat(t,(K,ee)=>{if(K)return this.close(l,()=>{s&&s(F)});L(null,ee)});return}if(o=k.size||0,o===0)return c=[],g();a=Buffer.allocUnsafe(o),g()};this.fstat(l,L)})}writeFile(t,e,r,s){if(this.server)throw new Error("Client-only method called in server mode");let i;if(typeof s=="function"?i=s:typeof r=="function"&&(i=r,r=void 0),typeof r=="string")r={encoding:r,mode:438,flag:"w"};else if(!r)r={encoding:"utf8",mode:438,flag:"w"};else if(typeof r!="object")throw new TypeError("Bad arguments");if(r.encoding&&!Buffer.isEncoding(r.encoding))throw new Error(`Unknown encoding: ${r.encoding}`);let o=r.flag||"w";this.open(t,o,r.mode,(a,c)=>{if(a)i&&i(a);else{let f=Buffer.isBuffer(e)?e:Buffer.from(""+e,r.encoding||"utf8"),l=/a/.test(o)?null:0;if(l===null){let u=(h,g)=>{if(h){this.stat(t,(y,_)=>{if(y)return this.close(c,()=>{i&&i(h)});u(null,_)});return}$a(this,c,f,0,f.length,g.size,i)};this.fstat(c,u);return}$a(this,c,f,0,f.length,l,i)}})}appendFile(t,e,r,s){if(this.server)throw new Error("Client-only method called in server mode");let i;if(typeof s=="function"?i=s:typeof r=="function"&&(i=r,r=void 0),typeof r=="string")r={encoding:r,mode:438,flag:"a"};else if(!r)r={encoding:"utf8",mode:438,flag:"a"};else if(typeof r!="object")throw new TypeError("Bad arguments");r.flag||(r=Object.assign({flag:"a"},r)),this.writeFile(t,e,r,i)}exists(t,e){if(this.server)throw new Error("Client-only method called in server mode");this.stat(t,r=>{e&&e(!r)})}unlink(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),s=9,i=Buffer.allocUnsafe(13+r);q(i,i.length-4,0),i[4]=ke.REMOVE;let o=this._writeReqid=this._writeReqid+1&ft;q(i,o,5),q(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:e};let a=Xe(this,i);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} REMOVE`)}rename(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");let s=Buffer.byteLength(t),i=Buffer.byteLength(e),o=9,a=Buffer.allocUnsafe(13+s+4+i);q(a,a.length-4,0),a[4]=ke.RENAME;let c=this._writeReqid=this._writeReqid+1&ft;q(a,c,5),q(a,s,o),a.utf8Write(t,o+=4,s),q(a,i,o+=s),a.utf8Write(e,o+=4,i),this._requests[c]={cb:r};let f=Xe(this,a);this._debug&&this._debug(`SFTP: Outbound: ${f?"Buffered":"Sending"} RENAME`)}mkdir(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");let s=0,i=0;typeof e=="function"&&(r=e,e=void 0),typeof e=="object"&&e!==null&&(e=hr(e),s=e.flags,i=e.nb);let o=Buffer.byteLength(t),a=9,c=Buffer.allocUnsafe(13+o+4+i);q(c,c.length-4,0),c[4]=ke.MKDIR;let f=this._writeReqid=this._writeReqid+1&ft;q(c,f,5),q(c,o,a),c.utf8Write(t,a+=4,o),q(c,s,a+=o),i&&(a+=4,i===Ne.length?c.set(Ne,a):zn(Ne,c,0,i,a),a+=i),this._requests[f]={cb:r};let l=Xe(this,c);this._debug&&this._debug(`SFTP: Outbound: ${l?"Buffered":"Sending"} MKDIR`)}rmdir(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),s=9,i=Buffer.allocUnsafe(13+r);q(i,i.length-4,0),i[4]=ke.RMDIR;let o=this._writeReqid=this._writeReqid+1&ft;q(i,o,5),q(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:e};let a=Xe(this,i);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} RMDIR`)}readdir(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");typeof e=="function"&&(r=e,e={}),(typeof e!="object"||e===null)&&(e={});let s=!(e&&e.full);if(!Buffer.isBuffer(t)&&typeof t!="string")throw new Error("missing directory handle or path");if(typeof t=="string"){let l=[],u=0,h=(g,y)=>{if(g)return r(g);this.readdir(y,e,(_,b)=>{let C=_&&_.code===et.EOF;if(_&&!C)return this.close(y,()=>r(_));if(C)return this.close(y,L=>{if(L)return r(L);r(void 0,l)});for(let L=0;L<b.length;++L,++u)l[u]=b[L];h(void 0,y)})};return this.opendir(t,h)}let i=t.length,o=9,a=Buffer.allocUnsafe(13+i);q(a,a.length-4,0),a[4]=ke.READDIR;let c=this._writeReqid=this._writeReqid+1&ft;q(a,c,5),q(a,i,o),a.set(t,o+=4),this._requests[c]={cb:s?(l,u)=>{if(typeof r=="function"){if(l)return r(l);for(let h=u.length-1;h>=0;--h)(u[h].filename==="."||u[h].filename==="..")&&u.splice(h,1);r(void 0,u)}}:r};let f=Xe(this,a);this._debug&&this._debug(`SFTP: Outbound: ${f?"Buffered":"Sending"} READDIR`)}fstat(t,e){if(this.server)throw new Error("Client-only method called in server mode");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");let r=t.length,s=9,i=Buffer.allocUnsafe(13+r);q(i,i.length-4,0),i[4]=ke.FSTAT;let o=this._writeReqid=this._writeReqid+1&ft;q(i,o,5),q(i,r,s),i.set(t,s+=4),this._requests[o]={cb:e};let a=Xe(this,i);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} FSTAT`)}stat(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),s=9,i=Buffer.allocUnsafe(13+r);q(i,i.length-4,0),i[4]=ke.STAT;let o=this._writeReqid=this._writeReqid+1&ft;q(i,o,5),q(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:e};let a=Xe(this,i);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} STAT`)}lstat(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),s=9,i=Buffer.allocUnsafe(13+r);q(i,i.length-4,0),i[4]=ke.LSTAT;let o=this._writeReqid=this._writeReqid+1&ft;q(i,o,5),q(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:e};let a=Xe(this,i);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} LSTAT`)}opendir(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),s=9,i=Buffer.allocUnsafe(13+r);q(i,i.length-4,0),i[4]=ke.OPENDIR;let o=this._writeReqid=this._writeReqid+1&ft;q(i,o,5),q(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:e};let a=Xe(this,i);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} OPENDIR`)}setstat(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");let s=0,i=0;typeof e=="object"&&e!==null?(e=hr(e),s=e.flags,i=e.nb):typeof e=="function"&&(r=e);let o=Buffer.byteLength(t),a=9,c=Buffer.allocUnsafe(13+o+4+i);q(c,c.length-4,0),c[4]=ke.SETSTAT;let f=this._writeReqid=this._writeReqid+1&ft;q(c,f,5),q(c,o,a),c.utf8Write(t,a+=4,o),q(c,s,a+=o),i&&(a+=4,i===Ne.length?c.set(Ne,a):zn(Ne,c,0,i,a),a+=i),this._requests[f]={cb:r};let l=Xe(this,c);this._debug&&this._debug(`SFTP: Outbound: ${l?"Buffered":"Sending"} SETSTAT`)}fsetstat(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");let s=0,i=0;typeof e=="object"&&e!==null?(e=hr(e),s=e.flags,i=e.nb):typeof e=="function"&&(r=e);let o=t.length,a=9,c=Buffer.allocUnsafe(13+o+4+i);q(c,c.length-4,0),c[4]=ke.FSETSTAT;let f=this._writeReqid=this._writeReqid+1&ft;q(c,f,5),q(c,o,a),c.set(t,a+=4),q(c,s,a+=o),i&&(a+=4,i===Ne.length?c.set(Ne,a):zn(Ne,c,0,i,a),a+=i),this._requests[f]={cb:r};let l=Xe(this,c);this._debug&&this._debug(`SFTP: Outbound: ${l?"Buffered":"Sending"} FSETSTAT`)}futimes(t,e,r,s){return this.fsetstat(t,{atime:Wr(e),mtime:Wr(r)},s)}utimes(t,e,r,s){return this.setstat(t,{atime:Wr(e),mtime:Wr(r)},s)}fchown(t,e,r,s){return this.fsetstat(t,{uid:e,gid:r},s)}chown(t,e,r,s){return this.setstat(t,{uid:e,gid:r},s)}fchmod(t,e,r){return this.fsetstat(t,{mode:e},r)}chmod(t,e,r){return this.setstat(t,{mode:e},r)}readlink(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),s=9,i=Buffer.allocUnsafe(13+r);q(i,i.length-4,0),i[4]=ke.READLINK;let o=this._writeReqid=this._writeReqid+1&ft;q(i,o,5),q(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:(c,f)=>{if(typeof e=="function"){if(c)return e(c);if(!f||!f.length)return e(new Error("Response missing link info"));e(void 0,f[0].filename)}}};let a=Xe(this,i);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} READLINK`)}symlink(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");let s=Buffer.byteLength(e),i=Buffer.byteLength(t),o=9,a=Buffer.allocUnsafe(13+s+4+i);q(a,a.length-4,0),a[4]=ke.SYMLINK;let c=this._writeReqid=this._writeReqid+1&ft;q(a,c,5),this._isOpenSSH?(q(a,i,o),a.utf8Write(t,o+=4,i),q(a,s,o+=i),a.utf8Write(e,o+=4,s)):(q(a,s,o),a.utf8Write(e,o+=4,s),q(a,i,o+=s),a.utf8Write(t,o+=4,i)),this._requests[c]={cb:r};let f=Xe(this,a);this._debug&&this._debug(`SFTP: Outbound: ${f?"Buffered":"Sending"} SYMLINK`)}realpath(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),s=9,i=Buffer.allocUnsafe(13+r);q(i,i.length-4,0),i[4]=ke.REALPATH;let o=this._writeReqid=this._writeReqid+1&ft;q(i,o,5),q(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:(c,f)=>{if(typeof e=="function"){if(c)return e(c);if(!f||!f.length)return e(new Error("Response missing path info"));e(void 0,f[0].filename)}}};let a=Xe(this,i);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} REALPATH`)}ext_openssh_rename(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");let s=this._extensions["posix-rename@openssh.com"];if(!s||s!=="1")throw new Error("Server does not support this extended request");let i=Buffer.byteLength(t),o=Buffer.byteLength(e),a=9,c=Buffer.allocUnsafe(41+i+4+o);q(c,c.length-4,0),c[4]=ke.EXTENDED;let f=this._writeReqid=this._writeReqid+1&ft;q(c,f,5),q(c,24,a),c.utf8Write("posix-rename@openssh.com",a+=4,24),q(c,i,a+=24),c.utf8Write(t,a+=4,i),q(c,o,a+=i),c.utf8Write(e,a+=4,o),this._requests[f]={cb:r};let l=Xe(this,c);if(this._debug){let u=l?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${u} posix-rename@openssh.com`)}}ext_openssh_statvfs(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=this._extensions["statvfs@openssh.com"];if(!r||r!=="2")throw new Error("Server does not support this extended request");let s=Buffer.byteLength(t),i=9,o=Buffer.allocUnsafe(36+s);q(o,o.length-4,0),o[4]=ke.EXTENDED;let a=this._writeReqid=this._writeReqid+1&ft;q(o,a,5),q(o,19,i),o.utf8Write("statvfs@openssh.com",i+=4,19),q(o,s,i+=19),o.utf8Write(t,i+=4,s),this._requests[a]={extended:"statvfs@openssh.com",cb:e};let c=Xe(this,o);if(this._debug){let f=c?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${f} statvfs@openssh.com`)}}ext_openssh_fstatvfs(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=this._extensions["fstatvfs@openssh.com"];if(!r||r!=="2")throw new Error("Server does not support this extended request");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");let s=t.length,i=9,o=Buffer.allocUnsafe(37+s);q(o,o.length-4,0),o[4]=ke.EXTENDED;let a=this._writeReqid=this._writeReqid+1&ft;q(o,a,5),q(o,20,i),o.utf8Write("fstatvfs@openssh.com",i+=4,20),q(o,s,i+=20),o.set(t,i+=4),this._requests[a]={extended:"fstatvfs@openssh.com",cb:e};let c=Xe(this,o);if(this._debug){let f=c?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${f} fstatvfs@openssh.com`)}}ext_openssh_hardlink(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["hardlink@openssh.com"]!=="1")throw new Error("Server does not support this extended request");let i=Buffer.byteLength(t),o=Buffer.byteLength(e),a=9,c=Buffer.allocUnsafe(37+i+4+o);q(c,c.length-4,0),c[4]=ke.EXTENDED;let f=this._writeReqid=this._writeReqid+1&ft;q(c,f,5),q(c,20,a),c.utf8Write("hardlink@openssh.com",a+=4,20),q(c,i,a+=20),c.utf8Write(t,a+=4,i),q(c,o,a+=i),c.utf8Write(e,a+=4,o),this._requests[f]={cb:r};let l=Xe(this,c);if(this._debug){let u=l?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${u} hardlink@openssh.com`)}}ext_openssh_fsync(t,e){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["fsync@openssh.com"]!=="1")throw new Error("Server does not support this extended request");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");let s=t.length,i=9,o=Buffer.allocUnsafe(34+s);q(o,o.length-4,0),o[4]=ke.EXTENDED;let a=this._writeReqid=this._writeReqid+1&ft;q(o,a,5),q(o,17,i),o.utf8Write("fsync@openssh.com",i+=4,17),q(o,s,i+=17),o.set(t,i+=4),this._requests[a]={cb:e};let c=Xe(this,o);this._debug&&this._debug(`SFTP: Outbound: ${c?"Buffered":"Sending"} fsync@openssh.com`)}ext_openssh_lsetstat(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["lsetstat@openssh.com"]!=="1")throw new Error("Server does not support this extended request");let i=0,o=0;typeof e=="object"&&e!==null?(e=hr(e),i=e.flags,o=e.nb):typeof e=="function"&&(r=e);let a=Buffer.byteLength(t),c=9,f=Buffer.allocUnsafe(37+a+4+o);q(f,f.length-4,0),f[4]=ke.EXTENDED;let l=this._writeReqid=this._writeReqid+1&ft;q(f,l,5),q(f,20,c),f.utf8Write("lsetstat@openssh.com",c+=4,20),q(f,a,c+=20),f.utf8Write(t,c+=4,a),q(f,i,c+=a),o&&(c+=4,o===Ne.length?f.set(Ne,c):zn(Ne,f,0,o,c),c+=o),this._requests[l]={cb:r};let u=Xe(this,f);if(this._debug){let h=u?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${h} lsetstat@openssh.com`)}}ext_openssh_expandPath(t,e){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["expand-path@openssh.com"]!=="1")throw new Error("Server does not support this extended request");let s=Buffer.byteLength(t),i=9,o=Buffer.allocUnsafe(40+s);q(o,o.length-4,0),o[4]=ke.EXTENDED;let a=this._writeReqid=this._writeReqid+1&ft;q(o,a,5),q(o,23,i),o.utf8Write("expand-path@openssh.com",i+=4,23),q(o,s,i+=20),o.utf8Write(t,i+=4,s),this._requests[a]={cb:(f,l)=>{if(typeof e=="function"){if(f)return e(f);if(!l||!l.length)return e(new Error("Response missing expanded path"));e(void 0,l[0].filename)}}};let c=Xe(this,o);if(this._debug){let f=c?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${f} expand-path@openssh.com`)}}ext_copy_data(t,e,r,s,i,o){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["copy-data"]!=="1")throw new Error("Server does not support this extended request");if(!Buffer.isBuffer(t))throw new Error("Source handle is not a Buffer");if(!Buffer.isBuffer(s))throw new Error("Destination handle is not a Buffer");let c=0,f=Buffer.allocUnsafe(26+t.length+8+8+4+s.length+8);q(f,f.length-4,c),c+=4,f[c]=ke.EXTENDED,++c;let l=this._writeReqid=this._writeReqid+1&ft;q(f,l,c),c+=4,q(f,9,c),c+=4,f.utf8Write("copy-data",c,9),c+=9,q(f,t.length,c),c+=4,f.set(t,c),c+=t.length;for(let h=7;h>=0;--h)f[c+h]=e&255,e/=256;c+=8;for(let h=7;h>=0;--h)f[c+h]=r&255,r/=256;c+=8,q(f,s.length,c),c+=4,f.set(s,c),c+=s.length;for(let h=7;h>=0;--h)f[c+h]=i&255,i/=256;this._requests[l]={cb:o};let u=Xe(this,f);if(this._debug){let h=u?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${h} copy-data`)}}ext_home_dir(t,e){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["home-directory"]!=="1")throw new Error("Server does not support this extended request");if(typeof t!="string")throw new TypeError("username is not a string");let s=0,i=Buffer.byteLength(t),o=Buffer.allocUnsafe(31+i);q(o,o.length-4,s),s+=4,o[s]=ke.EXTENDED,++s;let a=this._writeReqid=this._writeReqid+1&ft;q(o,a,s),s+=4,q(o,14,s),s+=4,o.utf8Write("home-directory",s,14),s+=14,q(o,i,s),s+=4,o.utf8Write(t,s,i),s+=i,this._requests[a]={cb:(f,l)=>{if(typeof e=="function"){if(f)return e(f);if(!l||!l.length)return e(new Error("Response missing home directory"));e(void 0,l[0].filename)}}};let c=Xe(this,o);if(this._debug){let f=c?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${f} home-directory`)}}ext_users_groups(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["users-groups-by-id@openssh.com"]!=="1")throw new Error("Server does not support this extended request");if(!Array.isArray(t))throw new TypeError("uids is not an array");for(let f of t)if(!Number.isInteger(f)||f<0||f>2**32-1)throw new Error("uid values must all be 32-bit unsigned integers");if(!Array.isArray(e))throw new TypeError("gids is not an array");for(let f of e)if(!Number.isInteger(f)||f<0||f>2**32-1)throw new Error("gid values must all be 32-bit unsigned integers");let i=0,o=Buffer.allocUnsafe(47+4*t.length+4+4*e.length);q(o,o.length-4,i),i+=4,o[i]=ke.EXTENDED,++i;let a=this._writeReqid=this._writeReqid+1&ft;q(o,a,i),i+=4,q(o,30,i),i+=4,o.utf8Write("users-groups-by-id@openssh.com",i,30),i+=30,q(o,4*t.length,i),i+=4;for(let f of t)q(o,f,i),i+=4;q(o,4*e.length,i),i+=4;for(let f of e)q(o,f,i),i+=4;this._requests[a]={extended:"users-groups-by-id@openssh.com",cb:r};let c=Xe(this,o);if(this._debug){let f=c?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${f} users-groups-by-id@openssh.com`)}}handle(t,e){if(!this.server)throw new Error("Server-only method called in client mode");if(!Buffer.isBuffer(e))throw new Error("handle is not a Buffer");let r=e.length;if(r>256)throw new Error("handle too large (> 256 bytes)");let s=9,i=Buffer.allocUnsafe(13+r);q(i,i.length-4,0),i[4]=en.HANDLE,q(i,t,5),q(i,r,s),r&&i.set(e,s+=4);let o=Xe(this,i);this._debug&&this._debug(`SFTP: Outbound: ${o?"Buffered":"Sending"} HANDLE`)}status(t,e,r){if(!this.server)throw new Error("Server-only method called in client mode");if(!am.has(e))throw new Error(`Bad status code: ${e}`);r||(r="");let s=Buffer.byteLength(r),i=9,o=Buffer.allocUnsafe(17+s+4);q(o,o.length-4,0),o[4]=en.STATUS,q(o,t,5),q(o,e,i),q(o,s,i+=4),i+=4,s&&(o.utf8Write(r,i,s),i+=s),q(o,0,i);let a=Xe(this,o);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} STATUS`)}data(t,e,r){if(!this.server)throw new Error("Server-only method called in client mode");let s=Buffer.isBuffer(e);if(!s&&typeof e!="string")throw new Error("data is not a Buffer or string");let i;!s&&!r&&(r=void 0,i=!0);let o=s?e.length:Buffer.byteLength(e,r),a=9,c=Buffer.allocUnsafe(13+o);q(c,c.length-4,0),c[4]=en.DATA,q(c,t,5),q(c,o,a),o&&(s?c.set(e,a+=4):i?c.utf8Write(e,a+=4,o):c.write(e,a+=4,o,r));let f=Xe(this,c);this._debug&&this._debug(`SFTP: Outbound: ${f?"Buffered":"Sending"} DATA`)}name(t,e){if(!this.server)throw new Error("Server-only method called in client mode");if(!Array.isArray(e)){if(typeof e!="object"||e===null)throw new Error("names is not an object or array");e=[e]}let r=e.length,s=0,i,o=[];for(let l=0;l<r;++l){let u=e[l],h=!u||!u.filename||typeof u.filename!="string"?"":u.filename;s+=4+Buffer.byteLength(h);let g=!u||!u.longname||typeof u.longname!="string"?"":u.longname;if(s+=4+Buffer.byteLength(g),typeof u.attrs=="object"&&u.attrs!==null){if(i=hr(u.attrs),s+=4+i.nb,i.nb){let y;i.nb===Ne.length?y=new Uint8Array(Ne):(y=new Uint8Array(i.nb),zn(Ne,y,0,i.nb,0)),i.bytes=y}o.push(i)}else s+=4,o.push(null)}let a=9,c=Buffer.allocUnsafe(13+s);q(c,c.length-4,0),c[4]=en.NAME,q(c,t,5),q(c,r,a),a+=4;for(let l=0;l<r;++l){let u=e[l];{let g=!u||!u.filename||typeof u.filename!="string"?"":u.filename,y=Buffer.byteLength(g);q(c,y,a),a+=4,y&&(c.utf8Write(g,a,y),a+=y)}{let g=!u||!u.longname||typeof u.longname!="string"?"":u.longname,y=Buffer.byteLength(g);q(c,y,a),a+=4,y&&(c.utf8Write(g,a,y),a+=y)}let h=o[l];h?(q(c,h.flags,a),a+=4,h.flags&&h.bytes&&(c.set(h.bytes,a),a+=h.nb)):(q(c,0,a),a+=4)}let f=Xe(this,c);this._debug&&this._debug(`SFTP: Outbound: ${f?"Buffered":"Sending"} NAME`)}attrs(t,e){if(!this.server)throw new Error("Server-only method called in client mode");if(typeof e!="object"||e===null)throw new Error("attrs is not an object");e=hr(e);let r=e.flags,s=e.nb,i=9,o=Buffer.allocUnsafe(13+s);q(o,o.length-4,0),o[4]=en.ATTRS,q(o,t,5),q(o,r,i),s&&(i+=4,s===Ne.length?o.set(Ne,i):zn(Ne,o,0,s,i),i+=s);let a=Xe(this,o);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} ATTRS`)}};function hm(n){try{return Buffer.allocUnsafe(n)}catch(t){return t}}function Wd(n,t,e,r,s,i,o,a){let c=n._maxReadLen,f=Math.max(s-c,0);f&&(s=c);let l=t.length,u=9,h=i,g=Buffer.allocUnsafe(13+l+8+4);q(g,g.length-4,0),g[4]=ke.READ;let y=n._writeReqid=n._writeReqid+1&ft;q(g,y,5),q(g,l,u),g.set(t,u+=4),u+=l;for(let C=7;C>=0;--C)g[u+C]=h&255,h/=256;q(g,s,u+=8),typeof o!="function"&&(o=Qd);let _=a||{nb:0,position:i,off:r,origOff:r,len:void 0,overflow:void 0,cb:(C,L,F)=>{let k=_.len,K=_.overflow;if(C){if(o._wantEOFError||C.code!==et.EOF)return o(C)}else{if(F>k)return o(new Error("Received more data than requested"));if(F===k&&K){_.nb+=F,_.position+=F,_.off+=F,Wd(n,t,e,_.off,K,_.position,o,_);return}}F=F||0,_.origOff===0&&e.length===_.nb?L=e:L=Kr(e,_.origOff,_.origOff+_.nb+F),o(void 0,_.nb+F,L,_.position)},buffer:void 0};_.len=s,_.overflow=f,_.buffer=Kr(e,r,r+s),n._requests[y]=_;let b=Xe(n,g);n._debug&&n._debug(`SFTP: Outbound: ${b?"Buffered":"Sending"} READ`)}function Dd(n,t,e,r,s,i){let o=64,a=32768,c,f,l;typeof s=="function"?i=s:typeof s=="object"&&s!==null&&(typeof s.concurrency=="number"&&s.concurrency>0&&!isNaN(s.concurrency)&&(o=s.concurrency),typeof s.chunkSize=="number"&&s.chunkSize>0&&!isNaN(s.chunkSize)&&(a=s.chunkSize),typeof s.fileSize=="number"&&s.fileSize>0&&!isNaN(s.fileSize)&&(l=s.fileSize),typeof s.step=="function"&&(c=s.step),(typeof s.mode=="string"||typeof s.mode=="number")&&(f=qa(s.mode)));let u,h=0,g=0,y=!1,_,b,C,L=a*o;function F(k){if(y)return;y=!0;let K=0,ee;_||b?(ee=()=>{--K===0&&i(k)},_&&(n===jn||n.outgoing.state==="open")&&++K,b&&(t===jn||t.outgoing.state==="open")&&++K,_&&(n===jn||n.outgoing.state==="open")&&n.close(_,ee),b&&(t===jn||t.outgoing.state==="open")&&t.close(b,ee)):i(k)}n.open(e,"r",(k,K)=>{if(k)return F(k);_=K,l===void 0?n.fstat(_,ee):ee(null,{size:l});function ee(O,x){if(O){if(n!==jn){n.stat(e,(w,I)=>{if(w)return F(O);ee(null,I)});return}return F(O)}u=x.size,t.open(r,"w",(w,I)=>{if(w)return F(w);if(b=I,u<=0)return F();for(;L>u;){if(o===1){L=u;break}L-=a,--o}if(C=hm(L),C instanceof Error)return F(C);f!==void 0?t.fchmod(b,f,function Y(te){if(te){t.chmod(r,f,ce=>Y());return}G()}):G();function U(Y,te,ce,D,v,N){if(Y)return F(Y);v=v||0,t.write(b,C,v,te,D,H);function H(X){if(X)return F(X);if(g+=te,c&&c(g,te,u),te<N)return re(v,D+te,N-te);if(g===u){t.close(b,se=>{if(b=void 0,se)return F(se);n.close(_,ze=>{if(_=void 0,ze)return F(ze);i()})});return}if(h>=u)return;let fe=h+a>u?u-h:a;re(v,h,fe),h+=fe}}function R(Y,te,ce){return(D,v,N)=>{U(D,v,N,te,Y,ce)}}function re(Y,te,ce){n.read(_,C,Y,ce,te,R(Y,te,ce))}function G(){let Y=0,te=0;for(;h<u&&Y<o;){let ce=h+a>u?u-h:a;re(te,h,ce),te+=ce,h+=ce,++Y}}})}})}function $a(n,t,e,r,s,i,o){let a=typeof o=="function"?o:void 0;n.write(t,e,r,s,i,(c,f)=>{if(c)return n.close(t,()=>{a&&a(c)});f===s?n.close(t,a):(r+=f,s-=f,i+=f,$a(n,t,e,r,s,i,a))})}var Fs=class{constructor(t){this.mode=t&&t.mode,this.uid=t&&t.uid,this.gid=t&&t.gid,this.size=t&&t.size,this.atime=t&&t.atime,this.mtime=t&&t.mtime,this.extended=t&&t.extended}isDirectory(){return(this.mode&Zt.S_IFMT)===Zt.S_IFDIR}isFile(){return(this.mode&Zt.S_IFMT)===Zt.S_IFREG}isBlockDevice(){return(this.mode&Zt.S_IFMT)===Zt.S_IFBLK}isCharacterDevice(){return(this.mode&Zt.S_IFMT)===Zt.S_IFCHR}isSymbolicLink(){return(this.mode&Zt.S_IFMT)===Zt.S_IFLNK}isFIFO(){return(this.mode&Zt.S_IFMT)===Zt.S_IFIFO}isSocket(){return(this.mode&Zt.S_IFMT)===Zt.S_IFSOCK}};function hr(n){let t=0,e=0;if(typeof n=="object"&&n!==null){if(typeof n.size=="number"){t|=On.SIZE;let r=n.size;Ne[e++]=r/72057594037927940,Ne[e++]=r/281474976710656,Ne[e++]=r/1099511627776,Ne[e++]=r/4294967296,Ne[e++]=r/16777216,Ne[e++]=r/65536,Ne[e++]=r/256,Ne[e++]=r}if(typeof n.uid=="number"&&typeof n.gid=="number"){t|=On.UIDGID;let r=n.uid,s=n.gid;Ne[e++]=r>>>24,Ne[e++]=r>>>16,Ne[e++]=r>>>8,Ne[e++]=r,Ne[e++]=s>>>24,Ne[e++]=s>>>16,Ne[e++]=s>>>8,Ne[e++]=s}if(typeof n.mode=="number"||typeof n.mode=="string"){let r=qa(n.mode);t|=On.PERMISSIONS,Ne[e++]=r>>>24,Ne[e++]=r>>>16,Ne[e++]=r>>>8,Ne[e++]=r}if((typeof n.atime=="number"||Oa(n.atime))&&(typeof n.mtime=="number"||Oa(n.mtime))){let r=Wr(n.atime),s=Wr(n.mtime);t|=On.ACMODTIME,Ne[e++]=r>>>24,Ne[e++]=r>>>16,Ne[e++]=r>>>8,Ne[e++]=r,Ne[e++]=s>>>24,Ne[e++]=s>>>16,Ne[e++]=s>>>8,Ne[e++]=s}}return{flags:t,nb:e}}function Wr(n){if(typeof n=="number"&&n===n)return n;if(Oa(n))return parseInt(n.getTime()/1e3,10);throw new Error(`Cannot parse time: ${n}`)}function qa(n){if(typeof n=="number"&&n===n)return n;if(typeof n=="string")return qa(parseInt(n,8));throw new Error(`Cannot parse mode: ${n}`)}var Fa={r:Ie.READ,"r+":Ie.READ|Ie.WRITE,w:Ie.TRUNC|Ie.CREAT|Ie.WRITE,wx:Ie.TRUNC|Ie.CREAT|Ie.WRITE|Ie.EXCL,xw:Ie.TRUNC|Ie.CREAT|Ie.WRITE|Ie.EXCL,"w+":Ie.TRUNC|Ie.CREAT|Ie.READ|Ie.WRITE,"wx+":Ie.TRUNC|Ie.CREAT|Ie.READ|Ie.WRITE|Ie.EXCL,"xw+":Ie.TRUNC|Ie.CREAT|Ie.READ|Ie.WRITE|Ie.EXCL,a:Ie.APPEND|Ie.CREAT|Ie.WRITE,ax:Ie.APPEND|Ie.CREAT|Ie.WRITE|Ie.EXCL,xa:Ie.APPEND|Ie.CREAT|Ie.WRITE|Ie.EXCL,"a+":Ie.APPEND|Ie.CREAT|Ie.READ|Ie.WRITE,"ax+":Ie.APPEND|Ie.CREAT|Ie.READ|Ie.WRITE|Ie.EXCL,"xa+":Ie.APPEND|Ie.CREAT|Ie.READ|Ie.WRITE|Ie.EXCL};function qd(n){let t=Fa[n];return t!==void 0?t:null}var pm=(()=>{let n=Object.keys(Fa);return t=>{for(let e=0;e<n.length;++e){let r=n[e];if(Fa[r]===t)return r}return null}})();function qr(n){let t=M.readUInt32BE();if(t===void 0)return;let e=new Fs;if(t&On.SIZE){let r=M.readUInt64BE(n);if(r===void 0)return;e.size=r}if(t&On.UIDGID){let r=M.readUInt32BE(),s=M.readUInt32BE();if(s===void 0)return;e.uid=r,e.gid=s}if(t&On.PERMISSIONS){let r=M.readUInt32BE();if(r===void 0)return;e.mode=r}if(t&On.ACMODTIME){let r=M.readUInt32BE(),s=M.readUInt32BE();if(s===void 0)return;e.atime=r,e.mtime=s}if(t&On.EXTENDED){let r=M.readUInt32BE();if(r===void 0)return;let s={};for(let i=0;i<r;++i){let o=M.readString(!0),a=M.readString();if(a===void 0)return;s[o]=a}e.extended=s}return e}function Xe(n,t){let e=Kd(n,t);return e!==void 0?(n._buffer.push(e),!1):!0}function Kd(n,t){let e=n.outgoing;if(e.state!=="open")return;if(e.window===0)return n._waitWindow=!0,n._chunkcb=Od,t;let r,s=t.length,i=0;for(;s-i>0&&e.window>0;){let o=Math.min(s-i,e.window,e.packetSize);e.window-=o,e.window===0&&(n._waitWindow=!0,n._chunkcb=Od),i===0&&o===s?n._protocol.channelData(n.outgoing.id,t):n._protocol.channelData(n.outgoing.id,Kr(t,i,i+o)),i+=o}return s-i>0&&(i>0?r=Kr(t,i,s):r=t),r}function Od(){this._chunkcb=void 0;let n=this._buffer,t=0;for(;t<n.length;){let e=n[t],r=Kd(this,e);if(r!==void 0){r!==e&&(n[t]=r),t>0&&(this._buffer=n.slice(t));return}++t}t>0&&(this._buffer=[])}function st(n,t,e){let r=new Error(t);return r.level="sftp-protocol",!e&&n._debug&&n._debug(`SFTP: Inbound: ${t}`),n.emit("error",r),n.destroy(),Vd(n),!1}function Vd(n){let t=Object.keys(n._requests);if(t.length===0)return;let e=n._requests;n._requests={};let r=new Error("No response from server");for(let s=0;s<t.length;++s){let i=e[t[s]];typeof i.cb=="function"&&i.cb(r)}}function gm(n,t){let e=9,r=Buffer.allocUnsafe(31);q(r,r.length-4,0),r[4]=ke.EXTENDED;let s=n._writeReqid=n._writeReqid+1&ft;q(r,s,5),q(r,18,e),r.utf8Write("limits@openssh.com",e+=4,18),n._requests[s]={extended:"limits@openssh.com",cb:t};let i=Xe(n,r);if(n._debug){let o=i?"Buffered":"Sending";n._debug(`SFTP: Outbound: ${o} limits@openssh.com`)}}var mm={[en.VERSION]:(n,t)=>{if(n._version!==-1)return st(n,"Duplicate VERSION packet");let e={};M.init(t,1);let r=M.readUInt32BE();for(;M.avail();){let s=M.readString(!0),i=M.readString(!0);if(i===void 0){r=void 0;break}e[s]=i}if(M.clear(),r===void 0)return st(n,"Malformed VERSION packet");if(n._debug){let s=Object.keys(e);s.length?n._debug(`SFTP: Inbound: Received VERSION (v${r}, exts:${s})`):n._debug(`SFTP: Inbound: Received VERSION (v${r})`)}if(n._version=r,n._extensions=e,e["limits@openssh.com"]==="1")return gm(n,(s,i)=>{s||(i.maxPktLen>0&&(n._maxOutPktLen=i.maxPktLen),i.maxReadLen>0&&(n._maxReadLen=i.maxReadLen),i.maxWriteLen>0&&(n._maxWriteLen=i.maxWriteLen),n.maxOpenHandles=i.maxOpenHandles>0?i.maxOpenHandles:1/0),n.emit("ready")});n.emit("ready")},[en.STATUS]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readUInt32BE(),s=M.readString(!0);if(M.clear(),n._debug){let o=JSON.stringify(s);n._debug(`SFTP: Inbound: Received STATUS (id:${e}, ${r}, ${o})`)}let i=n._requests[e];if(delete n._requests[e],i&&typeof i.cb=="function"){if(r===et.OK){i.cb();return}let o=new Error(s||cm[r]||"Unknown status");o.code=r,i.cb(o)}},[en.HANDLE]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString();if(M.clear(),r===void 0)return e!==void 0&&delete n._requests[e],st(n,"Malformed HANDLE packet");n._debug&&n._debug(`SFTP: Inbound: Received HANDLE (id:${e})`);let s=n._requests[e];delete n._requests[e],s&&typeof s.cb=="function"&&s.cb(void 0,r)},[en.DATA]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r;if(e!==void 0&&(r=n._requests[e],delete n._requests[e]),r&&typeof r.cb=="function")if(r.buffer){let s=M.readString(r.buffer);if(M.clear(),s!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received DATA (id:${e}, ${s})`),r.cb(void 0,r.buffer,s);return}}else{let s=M.readString();if(M.clear(),s!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received DATA (id:${e}, ${s.length})`),r.cb(void 0,s);return}}else{let s=M.skipString();if(M.clear(),s!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received DATA (id:${e}, ${s})`);return}}return st(n,"Malformed DATA packet")},[en.NAME]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r;e!==void 0&&(r=n._requests[e],delete n._requests[e]);let s=M.readUInt32BE();if(s!==void 0){let i=[];for(let o=0;o<s;++o){let a=M.readString(!0),c=M.readString(!0),f=qr(n._biOpt);if(f===void 0){i=void 0;break}i.push({filename:a,longname:c,attrs:f})}if(i!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received NAME (id:${e}, ${i.length})`),M.clear(),r&&typeof r.cb=="function"&&r.cb(void 0,i);return}}return M.clear(),st(n,"Malformed NAME packet")},[en.ATTRS]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r;e!==void 0&&(r=n._requests[e],delete n._requests[e]);let s=qr(n._biOpt);if(M.clear(),s!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received ATTRS (id:${e})`),r&&typeof r.cb=="function"&&r.cb(void 0,s);return}return st(n,"Malformed ATTRS packet")},[en.EXTENDED]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE();if(e!==void 0){let r=n._requests[e];if(r)switch(delete n._requests[e],r.extended){case"statvfs@openssh.com":case"fstatvfs@openssh.com":{let s=n._biOpt,i={f_bsize:M.readUInt64BE(s),f_frsize:M.readUInt64BE(s),f_blocks:M.readUInt64BE(s),f_bfree:M.readUInt64BE(s),f_bavail:M.readUInt64BE(s),f_files:M.readUInt64BE(s),f_ffree:M.readUInt64BE(s),f_favail:M.readUInt64BE(s),f_sid:M.readUInt64BE(s),f_flag:M.readUInt64BE(s),f_namemax:M.readUInt64BE(s)};if(i.f_namemax===void 0)break;n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ${r.extended})`),M.clear(),typeof r.cb=="function"&&r.cb(void 0,i);return}case"limits@openssh.com":{let s={maxPktLen:M.readUInt64BE(),maxReadLen:M.readUInt64BE(),maxWriteLen:M.readUInt64BE(),maxOpenHandles:M.readUInt64BE()};if(s.maxOpenHandles===void 0)break;n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ${r.extended})`),M.clear(),typeof r.cb=="function"&&r.cb(void 0,s);return}case"users-groups-by-id@openssh.com":{let s=M.readUInt32BE();if(s===void 0)break;let i=new Array(s);for(let c=0;c<i.length;++c)i[c]=M.readString(!0);let o=M.readUInt32BE();if(o===void 0)break;let a=new Array(o);for(let c=0;c<a.length;++c)a[c]=M.readString(!0);if(a.length>0&&a[a.length-1]===void 0)break;n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ${r.extended})`),M.clear(),typeof r.cb=="function"&&r.cb(void 0,i,a);return}default:n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ???)`),M.clear(),typeof r.cb=="function"&&r.cb();return}else{n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ???)`),M.clear();return}}return M.clear(),st(n,"Malformed EXTENDED_REPLY packet")}},Am={[ke.INIT]:(n,t)=>{if(n._version!==-1)return st(n,"Duplicate INIT packet");let e={};M.init(t,1);let r=M.readUInt32BE();for(;M.avail();){let s=M.readString(!0),i=M.readString(!0);if(i===void 0){r=void 0;break}e[s]=i}if(M.clear(),r===void 0)return st(n,"Malformed INIT packet");if(n._debug){let s=Object.keys(e);s.length?n._debug(`SFTP: Inbound: Received INIT (v${r}, exts:${s})`):n._debug(`SFTP: Inbound: Received INIT (v${r})`)}Xe(n,lm),n._version=r,n._extensions=e,n.emit("ready")},[ke.OPEN]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0),s=M.readUInt32BE(),i=qr(n._biOpt);if(M.clear(),i===void 0)return st(n,"Malformed OPEN packet");n._debug&&n._debug(`SFTP: Inbound: Received OPEN (id:${e})`),n.emit("OPEN",e,r,s,i)||n.status(e,et.OP_UNSUPPORTED)},[ke.CLOSE]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString();if(M.clear(),r===void 0||r.length>256)return st(n,"Malformed CLOSE packet");n._debug&&n._debug(`SFTP: Inbound: Received CLOSE (id:${e})`),n.emit("CLOSE",e,r)||n.status(e,et.OP_UNSUPPORTED)},[ke.READ]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(),s=M.readUInt64BE(n._biOpt),i=M.readUInt32BE();if(M.clear(),i===void 0||r.length>256)return st(n,"Malformed READ packet");n._debug&&n._debug(`SFTP: Inbound: Received READ (id:${e})`),n.emit("READ",e,r,s,i)||n.status(e,et.OP_UNSUPPORTED)},[ke.WRITE]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(),s=M.readUInt64BE(n._biOpt),i=M.readString();if(M.clear(),i===void 0||r.length>256)return st(n,"Malformed WRITE packet");n._debug&&n._debug(`SFTP: Inbound: Received WRITE (id:${e})`),n.emit("WRITE",e,r,s,i)||n.status(e,et.OP_UNSUPPORTED)},[ke.LSTAT]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0);if(M.clear(),r===void 0)return st(n,"Malformed LSTAT packet");n._debug&&n._debug(`SFTP: Inbound: Received LSTAT (id:${e})`),n.emit("LSTAT",e,r)||n.status(e,et.OP_UNSUPPORTED)},[ke.FSTAT]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString();if(M.clear(),r===void 0||r.length>256)return st(n,"Malformed FSTAT packet");n._debug&&n._debug(`SFTP: Inbound: Received FSTAT (id:${e})`),n.emit("FSTAT",e,r)||n.status(e,et.OP_UNSUPPORTED)},[ke.SETSTAT]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0),s=qr(n._biOpt);if(M.clear(),s===void 0)return st(n,"Malformed SETSTAT packet");n._debug&&n._debug(`SFTP: Inbound: Received SETSTAT (id:${e})`),n.emit("SETSTAT",e,r,s)||n.status(e,et.OP_UNSUPPORTED)},[ke.FSETSTAT]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(),s=qr(n._biOpt);if(M.clear(),s===void 0||r.length>256)return st(n,"Malformed FSETSTAT packet");n._debug&&n._debug(`SFTP: Inbound: Received FSETSTAT (id:${e})`),n.emit("FSETSTAT",e,r,s)||n.status(e,et.OP_UNSUPPORTED)},[ke.OPENDIR]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0);if(M.clear(),r===void 0)return st(n,"Malformed OPENDIR packet");n._debug&&n._debug(`SFTP: Inbound: Received OPENDIR (id:${e})`),n.emit("OPENDIR",e,r)||n.status(e,et.OP_UNSUPPORTED)},[ke.READDIR]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString();if(M.clear(),r===void 0||r.length>256)return st(n,"Malformed READDIR packet");n._debug&&n._debug(`SFTP: Inbound: Received READDIR (id:${e})`),n.emit("READDIR",e,r)||n.status(e,et.OP_UNSUPPORTED)},[ke.REMOVE]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0);if(M.clear(),r===void 0)return st(n,"Malformed REMOVE packet");n._debug&&n._debug(`SFTP: Inbound: Received REMOVE (id:${e})`),n.emit("REMOVE",e,r)||n.status(e,et.OP_UNSUPPORTED)},[ke.MKDIR]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0),s=qr(n._biOpt);if(M.clear(),s===void 0)return st(n,"Malformed MKDIR packet");n._debug&&n._debug(`SFTP: Inbound: Received MKDIR (id:${e})`),n.emit("MKDIR",e,r,s)||n.status(e,et.OP_UNSUPPORTED)},[ke.RMDIR]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0);if(M.clear(),r===void 0)return st(n,"Malformed RMDIR packet");n._debug&&n._debug(`SFTP: Inbound: Received RMDIR (id:${e})`),n.emit("RMDIR",e,r)||n.status(e,et.OP_UNSUPPORTED)},[ke.REALPATH]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0);if(M.clear(),r===void 0)return st(n,"Malformed REALPATH packet");n._debug&&n._debug(`SFTP: Inbound: Received REALPATH (id:${e})`),n.emit("REALPATH",e,r)||n.status(e,et.OP_UNSUPPORTED)},[ke.STAT]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0);if(M.clear(),r===void 0)return st(n,"Malformed STAT packet");n._debug&&n._debug(`SFTP: Inbound: Received STAT (id:${e})`),n.emit("STAT",e,r)||n.status(e,et.OP_UNSUPPORTED)},[ke.RENAME]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0),s=M.readString(!0);if(M.clear(),s===void 0)return st(n,"Malformed RENAME packet");n._debug&&n._debug(`SFTP: Inbound: Received RENAME (id:${e})`),n.emit("RENAME",e,r,s)||n.status(e,et.OP_UNSUPPORTED)},[ke.READLINK]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0);if(M.clear(),r===void 0)return st(n,"Malformed READLINK packet");n._debug&&n._debug(`SFTP: Inbound: Received READLINK (id:${e})`),n.emit("READLINK",e,r)||n.status(e,et.OP_UNSUPPORTED)},[ke.SYMLINK]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0),s=M.readString(!0);if(M.clear(),s===void 0)return st(n,"Malformed SYMLINK packet");n._debug&&n._debug(`SFTP: Inbound: Received SYMLINK (id:${e})`);let i;n._isOpenSSH?i=n.emit("SYMLINK",e,s,r):i=n.emit("SYMLINK",e,r,s),i||n.status(e,et.OP_UNSUPPORTED)},[ke.EXTENDED]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0);if(r===void 0)return M.clear(),st(n,"Malformed EXTENDED packet");let s;M.avail()&&(s=M.readRaw()),M.clear(),n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED (id:${e})`),n.emit("EXTENDED",e,r,s)||n.status(e,et.OP_UNSUPPORTED)}},{ERR_INVALID_ARG_TYPE:Em,ERR_OUT_OF_RANGE:$s,validateNumber:_m}=Ld(),Md=128,zt,Ha=[];function ym(n){Ha.length>0?zt=Ha.pop():zt=Buffer.allocUnsafe(n),zt.used=0}function Qa(n,t){if(!Number.isSafeInteger(n))throw _m(n,t),Number.isInteger(n)?new $s(t,">= 0 and <= 2 ** 53 - 1",n):new $s(t,"an integer",n);if(n<0)throw new $s(t,">= 0 and <= 2 ** 53 - 1",n)}function Da(n){return n+7&-8}function Mn(n,t,e){if(e===void 0)e={};else if(typeof e=="string")e={encoding:e};else{if(e===null||typeof e!="object")throw new TypeError('"options" argument must be a string or an object');e=Object.create(e)}if(e.highWaterMark===void 0&&(e.highWaterMark=64*1024),e.emitClose=!1,e.autoDestroy=!1,Fd.call(this,e),this.path=t,this.flags=e.flags===void 0?"r":e.flags,this.mode=e.mode===void 0?438:e.mode,this.start=e.start,this.end=e.end,this.autoClose=e.autoClose===void 0?!0:e.autoClose,this.pos=0,this.bytesRead=0,this.isClosed=!1,this.handle=e.handle===void 0?null:e.handle,this.sftp=n,this._opening=!1,this.start!==void 0&&(Qa(this.start,"start"),this.pos=this.start),this.end===void 0)this.end=1/0;else if(this.end!==1/0&&(Qa(this.end,"end"),this.start!==void 0&&this.start>this.end))throw new $s("start",`<= "end" (here: ${this.end})`,this.start);this.on("end",function(){this.autoClose&&this.destroy()}),Buffer.isBuffer(this.handle)||this.open()}Hd(Mn,Fd);Mn.prototype.open=function(){this._opening||(this._opening=!0,this.sftp.open(this.path,this.flags,this.mode,(n,t)=>{if(this._opening=!1,n){this.emit("error",n),this.autoClose&&this.destroy();return}this.handle=t,this.emit("open",t),this.emit("ready"),this.read()}))};Mn.prototype._read=function(n){if(!Buffer.isBuffer(this.handle))return this.once("open",()=>this._read(n));if(this.destroyed)return;(!zt||zt.length-zt.used<Md)&&ym(this.readableHighWaterMark||this._readableState.highWaterMark);let t=zt,e=Math.min(zt.length-zt.used,n),r=zt.used;if(this.end!==void 0&&(e=Math.min(this.end-this.pos+1,e)),e<=0)return this.push(null);this.sftp.read(this.handle,zt,zt.used,e,this.pos,(s,i)=>{if(s){this.emit("error",s),this.autoClose&&this.destroy();return}let o=null;if(r+e===t.used&&t===zt)t.used=Da(t.used+i-e);else{let a=r+e&-8,c=Da(r+i);a-c>=Md&&Ha.push(t.slice(c,a))}i>0&&(this.bytesRead+=i,o=t.slice(r,r+i)),this.pos+=i,this.push(o)}),zt.used=Da(zt.used+e)};Mn.prototype._destroy=function(n,t){if(this._opening&&!Buffer.isBuffer(this.handle)){this.once("open",$d.bind(null,this,t,n));return}$d(this,t,n),this.handle=null,this._opening=!1};function $d(n,t,e){if(!n.handle)return r();n.sftp.close(n.handle,r);function r(s){s=s||e,t(s),n.isClosed=!0,s||n.emit("close")}}Mn.prototype.close=function(n){this.destroy(null,n)};Object.defineProperty(Mn.prototype,"pending",{get(){return this.handle===null},configurable:!0});function un(n,t,e){if(e===void 0)e={};else if(typeof e=="string")e={encoding:e};else{if(e===null||typeof e!="object")throw new TypeError('"options" argument must be a string or an object');e=Object.create(e)}e.emitClose=!1,e.autoDestroy=!1,Wa.call(this,e),this.path=t,this.flags=e.flags===void 0?"w":e.flags,this.mode=e.mode===void 0?438:e.mode,this.start=e.start,this.autoClose=e.autoClose===void 0?!0:e.autoClose,this.pos=0,this.bytesWritten=0,this.isClosed=!1,this.handle=e.handle===void 0?null:e.handle,this.sftp=n,this._opening=!1,this.start!==void 0&&(Qa(this.start,"start"),this.pos=this.start),e.encoding&&this.setDefaultEncoding(e.encoding),this.on("finish",function(){this._writableState.finalCalled||this.autoClose&&this.destroy()}),Buffer.isBuffer(this.handle)||this.open()}Hd(un,Wa);un.prototype._final=function(n){this.autoClose&&this.destroy(),n()};un.prototype.open=function(){this._opening||(this._opening=!0,this.sftp.open(this.path,this.flags,this.mode,(n,t)=>{if(this._opening=!1,n){this.emit("error",n),this.autoClose&&this.destroy();return}this.handle=t;let e=r=>{if(r){this.sftp.chmod(this.path,this.mode,s=>e());return}if(this.flags[0]==="a"){let s=(i,o)=>{if(i){this.sftp.stat(this.path,(a,c)=>{if(a){this.destroy(),this.emit("error",i);return}s(null,c)});return}this.pos=o.size,this.emit("open",t),this.emit("ready")};this.sftp.fstat(t,s);return}this.emit("open",t),this.emit("ready")};this.sftp.fchmod(t,this.mode,e)}))};un.prototype._write=function(n,t,e){if(!Buffer.isBuffer(n)){let r=new Em("data","Buffer",n);return this.emit("error",r)}if(!Buffer.isBuffer(this.handle))return this.once("open",function(){this._write(n,t,e)});this.sftp.write(this.handle,n,0,n.length,this.pos,(r,s)=>{if(r)return this.autoClose&&this.destroy(),e(r);this.bytesWritten+=s,e()}),this.pos+=n.length};un.prototype._writev=function(n,t){if(!Buffer.isBuffer(this.handle))return this.once("open",function(){this._writev(n,t)});let e=this.sftp,r=this.handle,s=n.length,i=(o,a)=>{if(o)return this.destroy(),t(o);this.bytesWritten+=a,--s===0&&t()};for(let o=0;o<n.length;++o){let a=n[o].chunk;e.write(r,a,0,a.length,this.pos,i),this.pos+=a.length}};typeof Wa.prototype.destroy!="function"&&(un.prototype.destroy=Mn.prototype.destroy);un.prototype._destroy=Mn.prototype._destroy;un.prototype.close=function(n){if(n){if(this.isClosed){process.nextTick(n);return}this.on("close",n)}this.autoClose||this.on("finish",this.destroy.bind(this)),this.end()};un.prototype.destroySoon=un.prototype.end;Object.defineProperty(un.prototype,"pending",{get(){return this.handle===null},configurable:!0});Gd.exports={flagsToString:pm,OPEN_MODE:Ie,SFTP:Ma,Stats:Fs,STATUS_CODE:et,stringToFlags:qd}});var ja=at((Jx,Xd)=>{"use strict";var{Duplex:bm,Readable:xm,Writable:Sm}=require("stream"),{CHANNEL_EXTENDED_DATATYPE:{STDERR:Yd}}=Ln(),{bufferSlice:Hs}=hn(),wm=32*1024,Ri=2*1024*1024,Ya=Ri/2,Ka=class extends xm{constructor(t,e){super(e),this._channel=t}_read(t){this._channel._waitChanDrain&&(this._channel._waitChanDrain=!1,this._channel.incoming.window<=Ya&&za(this._channel))}},Va=class extends Sm{constructor(t){super({highWaterMark:Ri}),this._channel=t}_write(t,e,r){let s=this._channel,i=s._client._protocol,o=s.outgoing,a=o.packetSize,c=o.id,f=o.window,l=t.length,u=0;if(o.state==="open"){for(;l-u>0&&f>0;){let h=l-u;h>f&&(h=f),h>a&&(h=a),u===0&&h===l?i.channelExtData(c,t,Yd):i.channelExtData(c,Hs(t,u,u+h),Yd),u+=h,f-=h}if(o.window=f,l-u>0){f===0&&(s._waitWindow=!0),u>0?s._chunkErr=Hs(t,u,l):s._chunkErr=t,s._chunkcbErr=r;return}r()}}},Ga=class extends bm{constructor(t,e,r){let s={highWaterMark:Ri,allowHalfOpen:!r||r&&r.allowHalfOpen!==!1,emitClose:!1};super(s),this.allowHalfOpen=s.allowHalfOpen;let i=!!(r&&r.server);this.server=i,this.type=e.type,this.subtype=void 0,this.incoming=e.incoming,this.outgoing=e.outgoing,this._callbacks=[],this._client=t,this._hasX11=!1,this._exit={code:void 0,signal:void 0,dump:void 0,desc:void 0},this.stdin=this.stdout=this,i?this.stderr=new Va(this):this.stderr=new Ka(this,s),this._waitWindow=!1,this._waitChanDrain=!1,this._chunk=void 0,this._chunkcb=void 0,this._chunkErr=void 0,this._chunkcbErr=void 0,this.on("finish",zd).on("prefinish",zd),this.on("end",jd).on("close",jd)}_read(t){this._waitChanDrain&&(this._waitChanDrain=!1,this.incoming.window<=Ya&&za(this))}_write(t,e,r){let s=this._client._protocol,i=this.outgoing,o=i.packetSize,a=i.id,c=i.window,f=t.length,l=0;if(i.state==="open"){for(;f-l>0&&c>0;){let u=f-l;u>c&&(u=c),u>o&&(u=o),l===0&&u===f?s.channelData(a,t):s.channelData(a,Hs(t,l,l+u)),l+=u,c-=u}if(i.window=c,f-l>0){c===0&&(this._waitWindow=!0),l>0?this._chunk=Hs(t,l,f):this._chunk=t,this._chunkcb=r;return}r()}}eof(){this.outgoing.state==="open"&&(this.outgoing.state="eof",this._client._protocol.channelEOF(this.outgoing.id))}close(){(this.outgoing.state==="open"||this.outgoing.state==="eof")&&(this.outgoing.state="closing",this._client._protocol.channelClose(this.outgoing.id))}destroy(){return this.end(),this.close(),this}setWindow(t,e,r,s){if(this.server)throw new Error("Client-only method called in server mode");this.type==="session"&&(this.subtype==="shell"||this.subtype==="exec")&&this.writable&&this.outgoing.state==="open"&&this._client._protocol.windowChange(this.outgoing.id,t,e,r,s)}signal(t){if(this.server)throw new Error("Client-only method called in server mode");this.type==="session"&&this.writable&&this.outgoing.state==="open"&&this._client._protocol.signal(this.outgoing.id,t)}exit(t,e,r){if(!this.server)throw new Error("Server-only method called in client mode");this.type==="session"&&this.writable&&this.outgoing.state==="open"&&(typeof t=="number"?this._client._protocol.exitStatus(this.outgoing.id,t):this._client._protocol.exitSignal(this.outgoing.id,t,e,r))}};function zd(){this.eof(),(this.server||!this.allowHalfOpen)&&this.close(),this.writable=!1}function jd(){this.readable=!1}function za(n){if(n.outgoing.state==="closed")return;let t=Ri-n.incoming.window;t<=0||(n.incoming.window+=t,n._client._protocol.channelWindowAdjust(n.outgoing.id,t))}Xd.exports={Channel:Ga,MAX_WINDOW:Ri,PACKET_SIZE:wm,windowAdjust:za,WINDOW_THRESHOLD:Ya}});var Za=at((Zx,eh)=>{"use strict";var{SFTP:Im}=Bi(),Ni=2**32-1;function Jd(n,t,e,r){if(n._chanMgr.remove(t),typeof r!="function")return;let s;e instanceof Error?s=e:typeof e=="object"&&e!==null?(s=new Error(`(SSH) Channel open failure: ${e.description}`),s.reason=e.reason):(s=new Error("(SSH) Channel open failure: server closed channel unexpectedly"),s.reason=""),r(s)}function Zd(n,t,e,r,s){if(typeof e=="function"){Jd(n,t,r,e);return}if(typeof e!="object"||e===null||e.incoming&&e.incoming.state==="closed"||(n._chanMgr.remove(t),e.server&&e.constructor.name==="Session"))return;e.incoming.state="closed",e.readable&&e.push(null),e.server?e.stderr.writable&&e.stderr.end():e.stderr.readable&&e.stderr.push(null),e.constructor!==Im&&(e.outgoing.state==="open"||e.outgoing.state==="eof")&&!s&&e.close(),e.outgoing.state==="closing"&&(e.outgoing.state="closed");let i=e._readableState,o=e._writableState;o&&!o.ending&&!o.finished&&!s&&e.end();let a=e._callbacks;e._callbacks=[];for(let c=0;c<a.length;++c)a[c](!0);if(e.server)!e.readable||e.destroyed||i&&i.endEmitted?e.emit("close"):e.once("end",()=>e.emit("close"));else{let c;switch(e.type){case"direct-streamlocal@openssh.com":case"direct-tcpip":c=()=>e.emit("close");break;default:{let l=e._exit;c=()=>{l.code===null?e.emit("close",l.code,l.signal,l.dump,l.desc):e.emit("close",l.code)}}}!e.readable||e.destroyed||i&&i.endEmitted?c():e.once("end",c);let f=e.stderr._readableState;!e.stderr.readable||e.stderr.destroyed||f&&f.endEmitted?e.stderr.emit("close"):e.stderr.once("end",()=>e.stderr.emit("close"))}}var Ja=class{constructor(t){this._client=t,this._channels={},this._cur=-1,this._count=0}add(t){let e;if(this._cur<Ni)e=++this._cur;else if(this._count===0)this._cur=0,e=0;else{let r=this._channels;for(let s=0;s<Ni;++s)if(r[s]===void 0){e=s;break}}return e===void 0?-1:(this._channels[e]=t||!0,++this._count,e)}update(t,e){if(typeof t!="number"||t<0||t>=Ni||!isFinite(t))throw new Error(`Invalid channel id: ${t}`);e&&this._channels[t]&&(this._channels[t]=e)}get(t){if(typeof t!="number"||t<0||t>=Ni||!isFinite(t))throw new Error(`Invalid channel id: ${t}`);return this._channels[t]}remove(t){if(typeof t!="number"||t<0||t>=Ni||!isFinite(t))throw new Error(`Invalid channel id: ${t}`);this._channels[t]&&(delete this._channels[t],this._count&&--this._count)}cleanup(t){let e=this._channels;this._channels={},this._cur=-1,this._count=0;let r=Object.keys(e),s=this._client;for(let i=0;i<r.length;++i){let o=+r[i],a=e[o];Zd(s,o,a._channel||a,t,!0)}}},Xa=(()=>{let n=Object.prototype.toString;return t=>n.call(t)==="[object RegExp]"})();function Cm(n,t,e){if(Array.isArray(n)&&n.length>0){for(let r=0;r<n.length;++r)if(e.indexOf(n[r])===-1)throw new Error(`Unsupported algorithm: ${n[r]}`);return n}if(typeof n=="object"&&n!==null){let r=Object.keys(n),s=t;for(let i=0;i<r.length;++i){let o=r[i],a=n[o];switch(o){case"append":if(Array.isArray(a)||(a=[a]),Array.isArray(a))for(let c=0;c<a.length;++c){let f=a[c];if(typeof f=="string"){if(!f||s.indexOf(f)!==-1)continue;if(e.indexOf(f)===-1)throw new Error(`Unsupported algorithm: ${f}`);s===t&&(s=s.slice()),s.push(f)}else if(Xa(f))for(let l=0;l<e.length;++l){let u=e[l];if(f.test(u)){if(s.indexOf(u)!==-1)continue;s===t&&(s=s.slice()),s.push(u)}}}break;case"prepend":if(Array.isArray(a)||(a=[a]),Array.isArray(a))for(let c=a.length;c>=0;--c){let f=a[c];if(typeof f=="string"){if(!f||s.indexOf(f)!==-1)continue;if(e.indexOf(f)===-1)throw new Error(`Unsupported algorithm: ${f}`);s===t&&(s=s.slice()),s.unshift(f)}else if(Xa(f))for(let l=e.length;l>=0;--l){let u=e[l];if(f.test(u)){if(s.indexOf(u)!==-1)continue;s===t&&(s=s.slice()),s.unshift(u)}}}break;case"remove":if(Array.isArray(a)||(a=[a]),Array.isArray(a))for(let c=0;c<a.length;++c){let f=a[c];if(typeof f=="string"){if(!f)continue;let l=s.indexOf(f);if(l===-1)continue;s===t&&(s=s.slice()),s.splice(l,1)}else if(Xa(f))for(let l=0;l<s.length;++l)f.test(s[l])&&(s===t&&(s=s.slice()),s.splice(l,1),--l)}break}}return s}return t}eh.exports={ChannelManager:Ja,generateAlgorithmList:Cm,onChannelOpenFailure:Jd,onCHANNEL_CLOSE:Zd,isWritable:n=>n&&n.writable&&n._readableState&&n._readableState.ended===!1}});var oc=at((eS,yh)=>{"use strict";var{createHash:vm,getHashes:km,randomFillSync:Bm}=require("crypto"),{Socket:Rm}=require("net"),{lookup:Nm}=require("dns"),Pm=require("events"),Tm=km(),{COMPAT:Ah,CHANNEL_EXTENDED_DATATYPE:{STDERR:Lm},CHANNEL_OPEN_FAILURE:Pi,DEFAULT_CIPHER:th,DEFAULT_COMPRESSION:nh,DEFAULT_KEX:rh,DEFAULT_MAC:ih,DEFAULT_SERVER_HOST_KEY:sh,DISCONNECT_REASON:oh,DISCONNECT_REASON_BY_VALUE:Um,SUPPORTED_CIPHER:Dm,SUPPORTED_COMPRESSION:Om,SUPPORTED_KEX:Mm,SUPPORTED_MAC:$m,SUPPORTED_SERVER_HOST_KEY:Fm}=Ln(),{init:Hm}=Kn(),Qm=La(),{parseKey:qs}=Yn(),{SFTP:Wm}=Bi(),{bufferCopy:ah,makeBufferParser:Eh,makeError:qm,readUInt32BE:Km,sigSSHToASN1:Vm,writeUInt32BE:ec}=hn(),{AgentContext:ch,createAgent:fh,isAgent:lh}=_a(),{Channel:_h,MAX_WINDOW:Ks,PACKET_SIZE:Vs,windowAdjust:uh,WINDOW_THRESHOLD:dh}=ja(),{ChannelManager:Gm,generateAlgorithmList:Ti,isWritable:Pt,onChannelOpenFailure:Ym,onCHANNEL_CLOSE:zm}=Za(),Qs=Eh(),Ws=Eh(),Li=/^OpenSSH_(?:(?![0-4])\d)|(?:\d{2,})/,ic=n=>{},sc=class extends Pm{constructor(){super(),this.config={host:void 0,port:void 0,localAddress:void 0,localPort:void 0,forceIPv4:void 0,forceIPv6:void 0,keepaliveCountMax:void 0,keepaliveInterval:void 0,readyTimeout:void 0,ident:void 0,username:void 0,password:void 0,privateKey:void 0,tryKeyboard:void 0,agent:void 0,allowAgentFwd:void 0,authHandler:void 0,hostHashAlgo:void 0,hostHashCb:void 0,strictVendor:void 0,debug:void 0},this._agent=void 0,this._readyTimeout=void 0,this._chanMgr=void 0,this._callbacks=void 0,this._forwarding=void 0,this._forwardingUnix=void 0,this._acceptX11=void 0,this._agentFwdEnabled=void 0,this._remoteVer=void 0,this._protocol=void 0,this._sock=void 0,this._resetKA=void 0}connect(t){if(this._sock&&Pt(this._sock))return this.once("close",()=>{this.connect(t)}),this.end(),this;this.config.host=t.hostname||t.host||"localhost",this.config.port=t.port||22,this.config.localAddress=typeof t.localAddress=="string"?t.localAddress:void 0,this.config.localPort=typeof t.localPort=="string"||typeof t.localPort=="number"?t.localPort:void 0,this.config.forceIPv4=t.forceIPv4||!1,this.config.forceIPv6=t.forceIPv6||!1,this.config.keepaliveCountMax=typeof t.keepaliveCountMax=="number"&&t.keepaliveCountMax>=0?t.keepaliveCountMax:3,this.config.keepaliveInterval=typeof t.keepaliveInterval=="number"&&t.keepaliveInterval>0?t.keepaliveInterval:0,this.config.readyTimeout=typeof t.readyTimeout=="number"&&t.readyTimeout>=0?t.readyTimeout:2e4,this.config.ident=typeof t.ident=="string"||Buffer.isBuffer(t.ident)?t.ident:void 0;let e={kex:void 0,serverHostKey:void 0,cs:{cipher:void 0,mac:void 0,compress:void 0,lang:[]},sc:void 0},r=!0;if(typeof t.algorithms=="object"&&t.algorithms!==null&&(e.kex=Ti(t.algorithms.kex,rh,Mm),e.kex!==rh&&(r=!1),e.serverHostKey=Ti(t.algorithms.serverHostKey,sh,Fm),e.serverHostKey!==sh&&(r=!1),e.cs.cipher=Ti(t.algorithms.cipher,th,Dm),e.cs.cipher!==th&&(r=!1),e.cs.mac=Ti(t.algorithms.hmac,ih,$m),e.cs.mac!==ih&&(r=!1),e.cs.compress=Ti(t.algorithms.compress,nh,Om),e.cs.compress!==nh&&(r=!1),r||(e.sc=e.cs)),typeof t.username=="string")this.config.username=t.username;else if(typeof t.user=="string")this.config.username=t.user;else throw new Error("Invalid username");this.config.password=typeof t.password=="string"?t.password:void 0,this.config.privateKey=typeof t.privateKey=="string"||Buffer.isBuffer(t.privateKey)?t.privateKey:void 0,this.config.localHostname=typeof t.localHostname=="string"?t.localHostname:void 0,this.config.localUsername=typeof t.localUsername=="string"?t.localUsername:void 0,this.config.tryKeyboard=t.tryKeyboard===!0,typeof t.agent=="string"&&t.agent.length?this.config.agent=fh(t.agent):lh(t.agent)?this.config.agent=t.agent:this.config.agent=void 0,this.config.allowAgentFwd=t.agentForward===!0&&this.config.agent!==void 0;let s=this.config.authHandler=typeof t.authHandler=="function"||Array.isArray(t.authHandler)?t.authHandler:void 0;this.config.strictVendor=typeof t.strictVendor=="boolean"?t.strictVendor:!0;let i=this.config.debug=typeof t.debug=="function"?t.debug:void 0;if(t.agentForward===!0&&!this.config.allowAgentFwd)throw new Error("You must set a valid agent path to allow agent forwarding");let o=this._callbacks=[];this._chanMgr=new Gm(this),this._forwarding={},this._forwardingUnix={},this._acceptX11=0,this._agentFwdEnabled=!1,this._agent=this.config.agent?this.config.agent:void 0,this._remoteVer=void 0;let a;if(this.config.privateKey){if(a=qs(this.config.privateKey,t.passphrase),a instanceof Error)throw new Error(`Cannot parse privateKey: ${a.message}`);if(Array.isArray(a)&&(a=a[0]),a.getPrivatePEM()===null)throw new Error("privateKey value does not contain a (valid) private key")}let c;if(typeof t.hostVerifier=="function"){let D=t.hostVerifier,v;Tm.indexOf(t.hostHash)!==-1&&(v=t.hostHash),c=(N,H)=>{v&&(N=vm(v).update(N).digest("hex"));let X=D(N,H);X!==void 0&&H(X)}}let f=this._sock=t.sock||new Rm,l=!1,u=!1;this._protocol&&this._protocol.cleanup();let h=i?(D,v,N)=>{i(`Debug output from server: ${JSON.stringify(N)}`)}:void 0,g,y=this._protocol=new Qm({ident:this.config.ident,offer:r?void 0:e,onWrite:D=>{Pt(f)&&f.write(D)},onError:D=>{D.level==="handshake"&&clearTimeout(this._readyTimeout),y._destruct||f.removeAllListeners("data"),this.emit("error",D);try{f.end()}catch{}},onHeader:D=>{u=!0,this._remoteVer=D.versions.software,D.greeting&&this.emit("greeting",D.greeting)},onHandshakeComplete:D=>{this.emit("handshake",D),l||(l=!0,y.service("ssh-userauth"))},debug:i,hostVerifier:c,messageHandlers:{DEBUG:h,DISCONNECT:(D,v,N)=>{if(v!==oh.BY_APPLICATION){N||(N=Um[v],N===void 0&&(N=`Unexpected disconnection reason: ${v}`));let H=new Error(N);H.code=v,this.emit("error",H)}f.end()},SERVICE_ACCEPT:(D,v)=>{v==="ssh-userauth"&&Y()},EXT_INFO:(D,v)=>{if(g===void 0){for(let N of v)if(N.name==="server-sig-algs"){g=N.algs;return}g=null}},USERAUTH_BANNER:(D,v)=>{this.emit("banner",v)},USERAUTH_SUCCESS:D=>{k(),clearTimeout(this._readyTimeout),this.emit("ready")},USERAUTH_FAILURE:(D,v,N)=>{if(x.keyAlgos){let H=x.keyAlgos[0][0];if(i&&i(`Client: ${x.type} (${H}) auth failed`),x.keyAlgos.shift(),x.keyAlgos.length){let[X,fe]=x.keyAlgos[0];switch(x.type){case"agent":y.authPK(x.username,x.agentCtx.currentKey(),X);return;case"publickey":y.authPK(x.username,x.key,X);return;case"hostbased":y.authHostbased(x.username,x.key,x.localHostname,x.localUsername,X,(se,ze)=>{let _t=x.key.sign(se,fe);if(_t instanceof Error)return _t.message=`Error while signing with key: ${_t.message}`,_t.level="client-authentication",this.emit("error",_t),Y();ze(_t)});return}}else x.keyAlgos=void 0}if(x.type==="agent"){let H=x.agentCtx.pos();return i&&i(`Client: Agent key #${H+1} failed`),te()}i&&i(`Client: ${x.type} auth failed`),w=N,I=v,Y()},USERAUTH_PASSWD_CHANGEREQ:(D,v)=>{x.type==="password"&&this.emit("change password",v,N=>{y.authPassword(this.config.username,this.config.password,N)})},USERAUTH_PK_OK:D=>{let v,N;if(x.keyAlgos&&([v,N]=x.keyAlgos[0]),x.type==="agent"){let H=x.agentCtx.currentKey();y.authPK(x.username,H,v,(X,fe)=>{let se={hash:N};x.agentCtx.sign(H,X,se,(ze,_t)=>{if(ze)ze.level="agent",this.emit("error",ze);else return fe(_t);te()})})}else x.type==="publickey"&&y.authPK(x.username,x.key,v,(H,X)=>{let fe=x.key.sign(H,N);if(fe instanceof Error)return fe.message=`Error signing data with key: ${fe.message}`,fe.level="client-authentication",this.emit("error",fe),Y();X(fe)})},USERAUTH_INFO_REQUEST:(D,v,N,H)=>{if(x.type==="keyboard-interactive"){if((Array.isArray(H)?H.length:0)===0){i&&i("Client: Sending automatic USERAUTH_INFO_RESPONSE"),y.authInfoRes();return}x.prompt(v,N,"",H,fe=>{y.authInfoRes(fe)})}},REQUEST_SUCCESS:(D,v)=>{o.length&&o.shift()(!1,v)},REQUEST_FAILURE:D=>{o.length&&o.shift()(!0)},GLOBAL_REQUEST:(D,v,N,H)=>{v==="hostkeys-00@openssh.com"?(eA(this,H,(X,fe)=>{X||this.emit("hostkeys",fe)}),N&&y.requestSuccess()):N&&y.requestFailure()},CHANNEL_OPEN:(D,v)=>{Jm(this,v)},CHANNEL_OPEN_CONFIRMATION:(D,v)=>{let N=this._chanMgr.get(v.recipient);if(typeof N!="function")return;let H=N.type==="sftp",fe={type:H?"session":N.type,incoming:{id:v.recipient,window:Ks,packetSize:Vs,state:"open"},outgoing:{id:v.sender,window:v.window,packetSize:v.packetSize,state:"open"}},se=H?new Wm(this,fe,{debug:i}):new _h(this,fe);this._chanMgr.update(v.recipient,se),N(void 0,se)},CHANNEL_OPEN_FAILURE:(D,v,N,H)=>{let X=this._chanMgr.get(v);if(typeof X!="function")return;Ym(this,v,{reason:N,description:H},X)},CHANNEL_DATA:(D,v,N)=>{let H=this._chanMgr.get(v);if(!(typeof H!="object"||H===null)&&H.incoming.window!==0){if(H.incoming.window-=N.length,H.push(N)===!1){H._waitChanDrain=!0;return}H.incoming.window<=dh&&uh(H)}},CHANNEL_EXTENDED_DATA:(D,v,N,H)=>{if(H!==Lm)return;let X=this._chanMgr.get(v);if(!(typeof X!="object"||X===null)&&X.incoming.window!==0){if(X.incoming.window-=N.length,!X.stderr.push(N)){X._waitChanDrain=!0;return}X.incoming.window<=dh&&uh(X)}},CHANNEL_WINDOW_ADJUST:(D,v,N)=>{let H=this._chanMgr.get(v);typeof H!="object"||H===null||(H.outgoing.window+=N,H._waitWindow&&(H._waitWindow=!1,H._chunk?H._write(H._chunk,null,H._chunkcb):H._chunkcb?H._chunkcb():H._chunkErr?H.stderr._write(H._chunkErr,null,H._chunkcbErr):H._chunkcbErr&&H._chunkcbErr()))},CHANNEL_SUCCESS:(D,v)=>{let N=this._chanMgr.get(v);typeof N!="object"||N===null||(this._resetKA(),N._callbacks.length&&N._callbacks.shift()(!1))},CHANNEL_FAILURE:(D,v)=>{let N=this._chanMgr.get(v);typeof N!="object"||N===null||(this._resetKA(),N._callbacks.length&&N._callbacks.shift()(!0))},CHANNEL_REQUEST:(D,v,N,H,X)=>{let fe=this._chanMgr.get(v);if(typeof fe!="object"||fe===null)return;let se=fe._exit;if(se.code===void 0){switch(N){case"exit-status":fe.emit("exit",se.code=X);return;case"exit-signal":fe.emit("exit",se.code=null,se.signal=`SIG${X.signal}`,se.dump=X.coreDumped,se.desc=X.errorMessage);return}H&&D.channelFailure(fe.outgoing.id)}},CHANNEL_EOF:(D,v)=>{let N=this._chanMgr.get(v);typeof N!="object"||N===null||N.incoming.state==="open"&&(N.incoming.state="eof",N.readable&&N.push(null),N.stderr.readable&&N.stderr.push(null))},CHANNEL_CLOSE:(D,v)=>{zm(this,v,this._chanMgr.get(v))}}});f.pause();let _=this.config.keepaliveInterval,b=this.config.keepaliveCountMax,C=0,L,F=()=>{if(++C>b){if(clearInterval(L),f.readable){let D=new Error("Keepalive timeout");D.level="client-timeout",this.emit("error",D),f.destroy()}return}Pt(f)?(o.push(k),y.ping()):clearInterval(L)};function k(){_>0&&(C=0,clearInterval(L),Pt(f)&&(L=setInterval(F,_)))}this._resetKA=k;let K=(()=>{let D=!1;return()=>{if(!D&&(D=!0,O&&!u)){let v=qm("Connection lost before handshake","protocol",!0);this.emit("error",v)}}})(),ee=(()=>{let D=!1;return()=>{D||(D=!0,O=!0,i&&i("Socket connected"),this.emit("connect"),Hm.then(()=>{y.start(),f.on("data",v=>{try{y.parse(v,0,v.length)}catch(N){this.emit("error",N);try{Pt(f)&&f.end()}catch{}}}),f.stderr&&typeof f.stderr.resume=="function"&&f.stderr.resume(),f.resume()}).catch(v=>{this.emit("error",v);try{Pt(f)&&f.end()}catch{}}))}})(),O=!1;f.on("connect",ee).on("timeout",()=>{this.emit("timeout")}).on("error",D=>{i&&i(`Socket error: ${D.message}`),clearTimeout(this._readyTimeout),D.level="client-socket",this.emit("error",D)}).on("end",()=>{i&&i("Socket ended"),K(),y.cleanup(),clearTimeout(this._readyTimeout),clearInterval(L),this.emit("end")}).on("close",()=>{i&&i("Socket closed"),K(),y.cleanup(),clearTimeout(this._readyTimeout),clearInterval(L),this.emit("close");let D=o;o=this._callbacks=[];let v=new Error("No response from server");for(let N=0;N<D.length;++N)D[N](v);this._chanMgr.cleanup(v)});let x,w=null,I=null,U=["none"];this.config.password!==void 0&&U.push("password"),a!==void 0&&U.push("publickey"),this._agent!==void 0&&U.push("agent"),this.config.tryKeyboard&&U.push("keyboard-interactive"),a!==void 0&&this.config.localHostname!==void 0&&this.config.localUsername!==void 0&&U.push("hostbased"),Array.isArray(s)?s=mh(s):typeof s!="function"&&(s=mh(U));let R=!1,re=D=>{if(!R){if(R=!0,D===!1){let v=new Error("All configured authentication methods failed");v.level="client-authentication",this.emit("error",v),this.end();return}if(typeof D=="string"){let v=D;if(U.indexOf(v)===-1)return G(`Authentication method not allowed: ${v}`);let N=this.config.username;switch(v){case"password":D={type:v,username:N,password:this.config.password};break;case"publickey":D={type:v,username:N,key:a};break;case"hostbased":D={type:v,username:N,key:a,localHostname:this.config.localHostname,localUsername:this.config.localUsername};break;case"agent":D={type:v,username:N,agentCtx:new ch(this._agent)};break;case"keyboard-interactive":D={type:v,username:N,prompt:(...H)=>this.emit("keyboard-interactive",...H)};break;case"none":D={type:v,username:N};break;default:return G(`Skipping unsupported authentication method: ${D}`)}}else{if(typeof D!="object"||D===null)return G(`Skipping invalid authentication attempt: ${D}`);{let v=D.username;if(typeof v!="string")return G(`Skipping invalid authentication attempt: ${D}`);let N=D.type;switch(N){case"password":{let{password:H}=D;if(typeof H!="string"&&!Buffer.isBuffer(H))return G("Skipping invalid password auth attempt");D={type:N,username:v,password:H};break}case"publickey":{let H=qs(D.key,D.passphrase);if(H instanceof Error)return G("Skipping invalid key auth attempt");if(!H.isPrivateKey())return G("Skipping non-private key");D={type:N,username:v,key:H};break}case"hostbased":{let{localHostname:H,localUsername:X}=D,fe=qs(D.key,D.passphrase);if(fe instanceof Error||typeof H!="string"||typeof X!="string")return G("Skipping invalid hostbased auth attempt");if(!fe.isPrivateKey())return G("Skipping non-private key");D={type:N,username:v,key:fe,localHostname:H,localUsername:X};break}case"agent":{let H=D.agent;if(typeof H=="string"&&H.length)H=fh(H);else if(!lh(H))return G(`Skipping invalid agent: ${D.agent}`);D={type:N,username:v,agentCtx:new ch(H)};break}case"keyboard-interactive":{let{prompt:H}=D;if(typeof H!="function")return G("Skipping invalid keyboard-interactive auth attempt");D={type:N,username:v,prompt:H};break}case"none":D={type:N,username:v};break;default:return G(`Skipping unsupported authentication method: ${D}`)}}}x=D;try{let v=x.username;switch(x.type){case"password":y.authPassword(v,x.password);break;case"publickey":{let N;if(x.keyAlgos=rc(this,x.key,g),x.keyAlgos)if(x.keyAlgos.length)N=x.keyAlgos[0][0];else return G("Skipping key authentication (no mutual hash algorithm)");y.authPK(v,x.key,N);break}case"hostbased":{let N,H;if(x.keyAlgos=rc(this,x.key,g),x.keyAlgos)if(x.keyAlgos.length)[N,H]=x.keyAlgos[0];else return G("Skipping hostbased authentication (no mutual hash algorithm)");y.authHostbased(v,x.key,x.localHostname,x.localUsername,N,(X,fe)=>{let se=x.key.sign(X,H);if(se instanceof Error)return se.message=`Error while signing with key: ${se.message}`,se.level="client-authentication",this.emit("error",se),Y();fe(se)});break}case"agent":x.agentCtx.init(N=>{if(N)return N.level="agent",this.emit("error",N),Y();te()});break;case"keyboard-interactive":y.authKeyboard(v);break;case"none":y.authNone(v);break}}finally{R=!1}}};function G(D){i&&i(D),process.nextTick(Y)}function Y(){R=!1;let D=s(I,w,re);R||D===void 0||re(D)}let te=()=>{if(x.type==="agent"){let D=x.agentCtx.nextKey();if(D===!1)i&&i("Agent: No more keys left to try"),i&&i("Client: agent auth failed"),Y();else{let v=x.agentCtx.pos(),N;if(x.keyAlgos=rc(this,D,g),x.keyAlgos)if(x.keyAlgos.length)N=x.keyAlgos[0][0];else{i&&i(`Agent: Skipping key #${v+1} (no mutual hash algorithm)`),te();return}i&&i(`Agent: Trying key #${v+1}`),y.authPK(x.username,D,N)}}},ce=()=>{this.config.readyTimeout>0&&(this._readyTimeout=setTimeout(()=>{let D=new Error("Timed out while waiting for handshake");D.level="client-timeout",this.emit("error",D),f.destroy()},this.config.readyTimeout))};if(t.sock)ce(),typeof f.connecting=="boolean"&&f.connecting||ee();else{let D=this.config.host,v=this.config.forceIPv4,N=this.config.forceIPv6;i&&i(`Client: Trying ${D} on port ${this.config.port} ...`);let H=()=>{ce(),f.connect({host:D,port:this.config.port,localAddress:this.config.localAddress,localPort:this.config.localPort}),f.setMaxListeners(0),f.setTimeout(typeof t.timeout=="number"?t.timeout:0)};!v&&!N||v&&N?H():Nm(D,v?4:6,(X,fe,se)=>{if(X){let ze=v?"IPv4":"IPv6",_t=new Error(`Error while looking up ${ze} address for '${D}': ${X}`);clearTimeout(this._readyTimeout),_t.level="client-dns",this.emit("error",_t),this.emit("close");return}D=fe,H()})}return this}end(){return this._sock&&Pt(this._sock)&&(this._protocol.disconnect(oh.BY_APPLICATION),this._sock.end()),this}destroy(){return this._sock&&Pt(this._sock)&&this._sock.destroy(),this}exec(t,e,r){if(!this._sock||!Pt(this._sock))throw new Error("Not connected");typeof e=="function"&&(r=e,e={});let s={allowHalfOpen:e.allowHalfOpen!==!1};return Vr(this,"session",s,(i,o)=>{if(i){r(i);return}let a=[];function c(f){if(f){o.close(),r(f);return}a.length&&a.shift()()}(this.config.allowAgentFwd===!0||e&&e.agentForward===!0&&this._agent!==void 0)&&a.push(()=>gh(o,c)),typeof e=="object"&&e!==null&&(typeof e.env=="object"&&e.env!==null&&tc(o,e.env),(typeof e.pty=="object"&&e.pty!==null||e.pty===!0)&&a.push(()=>ph(o,e.pty,c)),(typeof e.x11=="object"&&e.x11!==null||e.x11==="number"||e.x11===!0)&&a.push(()=>hh(o,e.x11,c))),a.push(()=>Xm(o,t,e,r)),a.shift()()}),this}shell(t,e,r){if(!this._sock||!Pt(this._sock))throw new Error("Not connected");return typeof t=="function"?(r=t,t=e=void 0):typeof e=="function"&&(r=e,e=void 0),t&&(t.x11!==void 0||t.env!==void 0)&&(e=t,t=void 0),Vr(this,"session",(s,i)=>{if(s){r(s);return}let o=[];function a(c){if(c){i.close(),r(c);return}o.length&&o.shift()()}(this.config.allowAgentFwd===!0||e&&e.agentForward===!0&&this._agent!==void 0)&&o.push(()=>gh(i,a)),t!==!1&&o.push(()=>ph(i,t,a)),typeof e=="object"&&e!==null&&(typeof e.env=="object"&&e.env!==null&&tc(i,e.env),(typeof e.x11=="object"&&e.x11!==null||e.x11==="number"||e.x11===!0)&&o.push(()=>hh(i,e.x11,a))),o.push(()=>jm(i,r)),o.shift()()}),this}subsys(t,e){if(!this._sock||!Pt(this._sock))throw new Error("Not connected");return Vr(this,"session",(r,s)=>{if(r){e(r);return}nc(s,t,(i,o)=>{if(i){e(i);return}e(void 0,o)})}),this}forwardIn(t,e,r){if(!this._sock||!Pt(this._sock))throw new Error("Not connected");let s=typeof r=="function";return s&&this._callbacks.push((i,o)=>{if(i){r(i!==!0?i:new Error(`Unable to bind to ${t}:${e}`));return}let a=e;e===0&&o&&o.length>=4&&(a=Km(o,0),this._protocol._compatFlags&Ah.DYN_RPORT_BUG||(e=a)),this._forwarding[`${t}:${e}`]=a,r(void 0,a)}),this._protocol.tcpipForward(t,e,s),this}unforwardIn(t,e,r){if(!this._sock||!Pt(this._sock))throw new Error("Not connected");let s=typeof r=="function";return s&&this._callbacks.push(i=>{if(i){r(i!==!0?i:new Error(`Unable to unbind from ${t}:${e}`));return}delete this._forwarding[`${t}:${e}`],r()}),this._protocol.cancelTcpipForward(t,e,s),this}forwardOut(t,e,r,s,i){if(!this._sock||!Pt(this._sock))throw new Error("Not connected");let o={srcIP:t,srcPort:e,dstIP:r,dstPort:s};return typeof i!="function"&&(i=ic),Vr(this,"direct-tcpip",o,i),this}openssh_noMoreSessions(t){if(!this._sock||!Pt(this._sock))throw new Error("Not connected");let e=typeof t=="function";return!this.config.strictVendor||this.config.strictVendor&&Li.test(this._remoteVer)?(e&&this._callbacks.push(r=>{if(r){t(r!==!0?r:new Error("Unable to disable future sessions"));return}t()}),this._protocol.openssh_noMoreSessions(e),this):e?(process.nextTick(t,new Error("strictVendor enabled and server is not OpenSSH or compatible version")),this):this}openssh_forwardInStreamLocal(t,e){if(!this._sock||!Pt(this._sock))throw new Error("Not connected");let r=typeof e=="function";return!this.config.strictVendor||this.config.strictVendor&&Li.test(this._remoteVer)?(r&&this._callbacks.push(s=>{if(s){e(s!==!0?s:new Error(`Unable to bind to ${t}`));return}this._forwardingUnix[t]=!0,e()}),this._protocol.openssh_streamLocalForward(t,r),this):r?(process.nextTick(e,new Error("strictVendor enabled and server is not OpenSSH or compatible version")),this):this}openssh_unforwardInStreamLocal(t,e){if(!this._sock||!Pt(this._sock))throw new Error("Not connected");let r=typeof e=="function";return!this.config.strictVendor||this.config.strictVendor&&Li.test(this._remoteVer)?(r&&this._callbacks.push(s=>{if(s){e(s!==!0?s:new Error(`Unable to unbind from ${t}`));return}delete this._forwardingUnix[t],e()}),this._protocol.openssh_cancelStreamLocalForward(t,r),this):r?(process.nextTick(e,new Error("strictVendor enabled and server is not OpenSSH or compatible version")),this):this}openssh_forwardOutStreamLocal(t,e){if(!this._sock||!Pt(this._sock))throw new Error("Not connected");return typeof e!="function"&&(e=ic),!this.config.strictVendor||this.config.strictVendor&&Li.test(this._remoteVer)?(Vr(this,"direct-streamlocal@openssh.com",{socketPath:t},e),this):(process.nextTick(e,new Error("strictVendor enabled and server is not OpenSSH or compatible version")),this)}sftp(t,e){if(!this._sock||!Pt(this._sock))throw new Error("Not connected");return typeof t=="function"&&(e=t,t=void 0),Vr(this,"sftp",(r,s)=>{if(r){e(r);return}let i=(o,a)=>{if(o){e(o);return}function c(){s.removeListener("ready",f),s.removeListener("error",l),s.removeListener("exit",u),s.removeListener("close",u)}function f(){c(),e(void 0,s)}function l(h){c(),e(h)}function u(h,g){c();let y;typeof h=="number"?y=`Received exit code ${h} while establishing SFTP session`:g!==void 0?y=`Received signal ${g} while establishing SFTP session`:y="Received unexpected SFTP session termination";let _=new Error(y);_.code=h,_.signal=g,e(_)}s.on("ready",f).on("error",l).on("exit",u).on("close",u),s._init()};typeof t=="object"&&t!==null?tc(s,t,o=>{if(o){e(o);return}nc(s,"sftp",i)}):nc(s,"sftp",i)}),this}setNoDelay(t){return this._sock&&typeof this._sock.setNoDelay=="function"&&this._sock.setNoDelay(t),this}};function Vr(n,t,e,r){let s=Ks,i=Vs;typeof e=="function"&&(r=e,e={});let o=(c,f)=>{r(c,f)};o.type=t;let a=n._chanMgr.add(o);if(a===-1){r(new Error("No free channels available"));return}switch(t){case"session":case"sftp":n._protocol.session(a,s,i);break;case"direct-tcpip":n._protocol.directTcpip(a,s,i,e);break;case"direct-streamlocal@openssh.com":n._protocol.openssh_directStreamLocal(a,s,i,e);break;default:throw new Error(`Unsupported channel type: ${t}`)}}function hh(n,t,e){let r={single:!1,protocol:"MIT-MAGIC-COOKIE-1",cookie:void 0,screen:0};typeof t=="function"?e=t:typeof t=="object"&&t!==null&&(typeof t.single=="boolean"&&(r.single=t.single),typeof t.screen=="number"&&(r.screen=t.screen),typeof t.protocol=="string"&&(r.protocol=t.protocol),typeof t.cookie=="string"?r.cookie=t.cookie:Buffer.isBuffer(t.cookie)&&(r.cookie=t.cookie.hexSlice(0,t.cookie.length))),r.cookie===void 0&&(r.cookie=Zm());let s=typeof e=="function";if(n.outgoing.state!=="open"){s&&e(new Error("Channel is not open"));return}s&&n._callbacks.push(i=>{if(i){e(i!==!0?i:new Error("Unable to request X11"));return}n._hasX11=!0,++n._client._acceptX11,n.once("close",()=>{n._client._acceptX11&&--n._client._acceptX11}),e()}),n._client._protocol.x11Forward(n.outgoing.id,r,s)}function ph(n,t,e){let r=24,s=80,i=640,o=480,a="vt100",c=null;typeof t=="function"?e=t:typeof t=="object"&&t!==null&&(typeof t.rows=="number"&&(r=t.rows),typeof t.cols=="number"&&(s=t.cols),typeof t.width=="number"&&(i=t.width),typeof t.height=="number"&&(o=t.height),typeof t.term=="string"&&(a=t.term),typeof t.modes=="object"&&(c=t.modes));let f=typeof e=="function";if(n.outgoing.state!=="open"){f&&e(new Error("Channel is not open"));return}f&&n._callbacks.push(l=>{if(l){e(l!==!0?l:new Error("Unable to request a pseudo-terminal"));return}e()}),n._client._protocol.pty(n.outgoing.id,r,s,o,i,a,c,f)}function gh(n,t){let e=typeof t=="function";if(n.outgoing.state!=="open"){e&&t(new Error("Channel is not open"));return}if(n._client._agentFwdEnabled){e&&t(!1);return}n._client._agentFwdEnabled=!0,n._callbacks.push(r=>{if(r){n._client._agentFwdEnabled=!1,e&&t(r!==!0?r:new Error("Unable to request agent forwarding"));return}e&&t()}),n._client._protocol.openssh_agentForward(n.outgoing.id,!0)}function jm(n,t){if(n.outgoing.state!=="open"){t(new Error("Channel is not open"));return}n._callbacks.push(e=>{if(e){t(e!==!0?e:new Error("Unable to open shell"));return}n.subtype="shell",t(void 0,n)}),n._client._protocol.shell(n.outgoing.id,!0)}function Xm(n,t,e,r){if(n.outgoing.state!=="open"){r(new Error("Channel is not open"));return}n._callbacks.push(s=>{if(s){r(s!==!0?s:new Error("Unable to exec"));return}n.subtype="exec",n.allowHalfOpen=e.allowHalfOpen!==!1,r(void 0,n)}),n._client._protocol.exec(n.outgoing.id,t,!0)}function tc(n,t,e){let r=typeof e=="function";if(n.outgoing.state!=="open"){r&&e(new Error("Channel is not open"));return}r&&n._callbacks.push(i=>{if(i){e(i!==!0?i:new Error("Unable to set environment"));return}e()});let s=Object.keys(t||{});for(let i=0;i<s.length;++i){let o=s[i],a=t[o];n._client._protocol.env(n.outgoing.id,o,a,r)}}function nc(n,t,e){if(n.outgoing.state!=="open"){e(new Error("Channel is not open"));return}n._callbacks.push(r=>{if(r){e(r!==!0?r:new Error(`Unable to start subsystem: ${t}`));return}n.subtype="subsystem",e(void 0,n)}),n._client._protocol.subsystem(n.outgoing.id,t,!0)}function Jm(n,t){let e=-1,r,s=()=>{let c={type:t.type,incoming:{id:e,window:Ks,packetSize:Vs,state:"open"},outgoing:{id:t.sender,window:t.window,packetSize:t.packetSize,state:"open"}},f=new _h(n,c);return n._chanMgr.update(e,f),n._protocol.channelOpenConfirm(t.sender,e,Ks,Vs),f},i=()=>{r===void 0&&(e===-1?r=Pi.RESOURCE_SHORTAGE:r=Pi.CONNECT_FAILED),e!==-1&&n._chanMgr.remove(e),n._protocol.channelOpenFail(t.sender,r,"")},o=()=>(e=n._chanMgr.add(),e===-1&&(r=Pi.RESOURCE_SHORTAGE,n.config.debug&&n.config.debug("Client: Automatic rejection of incoming channel open: no channels available")),e!==-1),a=t.data;switch(t.type){case"forwarded-tcpip":{let c=n._forwarding[`${a.destIP}:${a.destPort}`];if(c!==void 0&&o()){a.destPort===0&&(a.destPort=c),n.emit("tcp connection",a,s,i);return}break}case"forwarded-streamlocal@openssh.com":if(n._forwardingUnix[a.socketPath]!==void 0&&o()){n.emit("unix connection",a,s,i);return}break;case"auth-agent@openssh.com":if(n._agentFwdEnabled&&typeof n._agent.getStream=="function"&&o()){n._agent.getStream((c,f)=>{if(c)return i();let l=s();l.pipe(f).pipe(l)});return}break;case"x11":if(n._acceptX11!==0&&o()){n.emit("x11",a,s,i);return}break;default:r=Pi.UNKNOWN_CHANNEL_TYPE,n.config.debug&&n.config.debug(`Client: Automatic rejection of unsupported incoming channel open type: ${t.type}`)}r===void 0&&(r=Pi.ADMINISTRATIVELY_PROHIBITED,n.config.debug&&n.config.debug("Client: Automatic rejection of unexpected incoming channel open for: "+t.type)),i()}var Zm=(()=>{let n=Buffer.allocUnsafe(16);return()=>(Bm(n,0,16),n.hexSlice(0,16))})();function mh(n){if(!Array.isArray(n))throw new Error("authList must be an array");let t=0;return(e,r,s)=>t===n.length?!1:n[t++]}function eA(n,t,e){if(!n._sock||!Pt(n._sock))return;if(typeof e!="function"&&(e=ic),!Array.isArray(t))throw new TypeError("Invalid keys argument type");let r=[];for(let s of t){let i=qs(s);if(i instanceof Error)throw i;r.push(i)}if(!n.config.strictVendor||n.config.strictVendor&&Li.test(n._remoteVer)){n._callbacks.push((s,i)=>{if(s){e(s!==!0?s:new Error("Server failed to prove supplied keys"));return}let o=[],a=0;for(Qs.init(i,0);Qs.avail()&&a!==r.length;){let c=r[a++],f=c.getPublicSSH(),l=Qs.readString();Ws.init(l,0);let u=Ws.readString(!0),h=Ws.readString(),g;if(u!==c.type)if(c.type==="ssh-rsa")switch(u){case"rsa-sha2-256":g="sha256";break;case"rsa-sha2-512":g="sha512";break;default:continue}else continue;let y=n._protocol._kex.sessionID,_=Buffer.allocUnsafe(37+y.length+4+f.length),b=0;ec(_,29,b),_.utf8Write("hostkeys-prove-00@openssh.com",b+=4,29),ec(_,y.length,b+=29),ah(y,_,0,y.length,b+=4),ec(_,f.length,b+=y.length),ah(f,_,0,f.length,b+=4),(h=Vm(h,u))&&c.verify(_,h,g)===!0&&o.push(c)}Ws.clear(),Qs.clear(),e(null,o)}),n._protocol.openssh_hostKeysProve(r);return}process.nextTick(e,new Error("strictVendor enabled and server is not OpenSSH or compatible version"))}function rc(n,t,e){switch(t.type){case"ssh-rsa":if(n._protocol._compatFlags&Ah.IMPLY_RSA_SHA2_SIGALGS&&(Array.isArray(e)?e=["rsa-sha2-256","rsa-sha2-512",...e]:e=["rsa-sha2-256","rsa-sha2-512"]),Array.isArray(e)){if(e.indexOf("rsa-sha2-256")!==-1)return[["rsa-sha2-256","sha256"]];if(e.indexOf("rsa-sha2-512")!==-1)return[["rsa-sha2-512","sha512"]];if(e.indexOf("ssh-rsa")===-1)return[]}return[["ssh-rsa","sha1"]]}}yh.exports=sc});var xh=at(bh=>{"use strict";var{Agent:cc}=require("http"),{Agent:tA}=require("https"),{connect:nA}=require("tls"),ac;for(let n of[cc,tA]){class t extends n{constructor(r,s){super(s),this._connectCfg=r,this._defaultSrcIP=s&&s.srcIP||"localhost"}createConnection(r,s){let i=r&&r.localAddress||this._defaultSrcIP,o=r&&r.localPort||0,a=r.host,c=r.port;ac===void 0&&(ac=oc());let f=new ac,l=!1;f.on("ready",()=>{f.forwardOut(i,o,a,c,(u,h)=>{if(l=!0,u)return f.end(),s(u);h.once("close",()=>f.end()),s(null,rA(h,n,r))})}).on("error",s).on("close",()=>{l||s(new Error("Unexpected connection close"))}).connect(this._connectCfg)}}bh[n===cc?"SSHTTPAgent":"SSHTTPSAgent"]=t}function Ui(){}function rA(n,t,e){if(t===cc)return n.setKeepAlive=Ui,n.setNoDelay=Ui,n.setTimeout=Ui,n.ref=Ui,n.unref=Ui,n.destroySoon=n.destroy,n;e.socket=n;let r=nA(e),s=(()=>{let i=!1;return()=>{i||(i=!0,n.isPaused()&&n.resume())}})();return r.on("end",s).on("close",s),r}});var wh=at((nS,dc)=>{"use strict";var{Server:iA}=require("net"),Oi=require("events"),{listenerCount:Kt}=Oi,{CHANNEL_OPEN_FAILURE:Gr,DEFAULT_CIPHER:sA,DEFAULT_COMPRESSION:oA,DEFAULT_KEX:aA,DEFAULT_MAC:cA,DEFAULT_SERVER_HOST_KEY:fA,DISCONNECT_REASON:Yr,DISCONNECT_REASON_BY_VALUE:lA,SUPPORTED_CIPHER:uA,SUPPORTED_COMPRESSION:dA,SUPPORTED_KEX:hA,SUPPORTED_MAC:pA,SUPPORTED_SERVER_HOST_KEY:gA}=Ln(),{init:mA}=Kn(),{KexInit:AA}=Bs(),{parseKey:Sh}=Yn(),EA=La(),{SFTP:_A}=Bi(),{writeUInt32BE:yA}=hn(),{Channel:zr,MAX_WINDOW:Xn,PACKET_SIZE:Jn,windowAdjust:bA,WINDOW_THRESHOLD:xA}=ja(),{ChannelManager:SA,generateAlgorithmList:Di,isWritable:Gs,onChannelOpenFailure:wA,onCHANNEL_CLOSE:IA}=Za(),CA=10,Zn=class extends Oi{constructor(t,e,r,s,i){super(),this.username=this.user=e,this.service=r,this.method=s,this._initialResponse=!1,this._finalResponse=!1,this._multistep=!1,this._cbfinal=(o,a,c)=>{this._finalResponse||(this._finalResponse=!0,i(this,o,a,c))},this._protocol=t}accept(){this._cleanup&&this._cleanup(),this._initialResponse=!0,this._cbfinal(!0)}reject(t,e){this._cleanup&&this._cleanup(),this._initialResponse=!0,this._cbfinal(!1,t,e)}},Ys=class extends Zn{constructor(t,e,r,s,i,o){super(t,e,r,s,o),this._multistep=!0,this._cb=void 0,this._onInfoResponse=a=>{let c=this._cb;c&&(this._cb=void 0,c(a))},this.submethods=i,this.on("abort",()=>{this._cb&&this._cb(new Error("Authentication request aborted"))})}prompt(t,e,r,s){Array.isArray(t)||(t=[t]),typeof e=="function"?(s=e,e=r=void 0):typeof r=="function"?(s=r,r=void 0):typeof s!="function"&&(s=void 0);for(let i=0;i<t.length;++i)typeof t[i]=="string"&&(t[i]={prompt:t[i],echo:!0});this._cb=s,this._initialResponse=!0,this._protocol.authInfoReq(e,r,t)}},lc=class extends Zn{constructor(t,e,r,s,i,o){super(t,e,r,s,o),this.key={algo:i.keyAlgo,data:i.key},this.hashAlgo=i.hashAlgo,this.signature=i.signature,this.blob=i.blob}accept(){this.signature?Zn.prototype.accept.call(this):(this._initialResponse=!0,this._protocol.authPKOK(this.key.algo,this.key.data))}},uc=class extends Zn{constructor(t,e,r,s,i,o){super(t,e,r,s,o),this.key={algo:i.keyAlgo,data:i.key},this.hashAlgo=i.hashAlgo,this.signature=i.signature,this.blob=i.blob,this.localHostname=i.localHostname,this.localUsername=i.localUsername}},zs=class extends Zn{constructor(t,e,r,s,i,o){super(t,e,r,s,o),this.password=i,this._changeCb=void 0}requestChange(t,e){if(this._changeCb)throw new Error("Change request already in progress");if(typeof t!="string")throw new Error("prompt argument must be a string");if(typeof e!="function")throw new Error("Callback argument must be a function");this._changeCb=e,this._protocol.authPasswdChg(t)}},vn=class extends Oi{constructor(t,e,r){super(),this.type="session",this.subtype=void 0,this.server=!0,this._ending=!1,this._channel=void 0,this._chanInfo={type:"session",incoming:{id:r,window:Xn,packetSize:Jn,state:"open"},outgoing:{id:e.sender,window:e.window,packetSize:e.packetSize,state:"open"}}}},on=class extends Oi{constructor(t,e){if(super(),typeof t!="object"||t===null)throw new Error("Missing configuration object");let r=Object.create(null),s=[],i=t.hostKeys;if(!Array.isArray(i))throw new Error("hostKeys must be an array");let o=typeof t.algorithms=="object"&&t.algorithms!==null?t.algorithms:{},a=Di(o.serverHostKey,fA,gA);for(let h=0;h<i.length;++h){let g;if(Buffer.isBuffer(i[h])||typeof i[h]=="string"?g=Sh(i[h]):g=Sh(i[h].key,i[h].passphrase),g instanceof Error)throw new Error(`Cannot parse privateKey: ${g.message}`);if(Array.isArray(g)&&(g=g[0]),g.getPrivatePEM()===null)throw new Error("privateKey value contains an invalid private key");if(!s.includes(g.type))if(g.type==="ssh-rsa"){let y=a.indexOf("ssh-rsa"),_=a.indexOf("rsa-sha2-256"),b=a.indexOf("rsa-sha2-512");y===-1&&(y=1/0),[y,_,b].sort(vA).forEach(C=>{if(C===-1)return;let L;switch(C){case y:L="ssh-rsa";break;case _:L="rsa-sha2-256";break;case b:L="rsa-sha2-512";break;default:return}r[L]=g,s.push(L)})}else r[g.type]=g,s.push(g.type)}let c={kex:Di(o.kex,aA,hA).concat(["kex-strict-s-v00@openssh.com"]),serverHostKey:s,cs:{cipher:Di(o.cipher,sA,uA),mac:Di(o.hmac,cA,pA),compress:Di(o.compress,oA,dA),lang:[]},sc:void 0};c.sc=c.cs,typeof e=="function"&&this.on("connection",e);let f=typeof t.debug=="function"?t.debug:void 0,l=t.ident?Buffer.from(t.ident):void 0,u=new AA(c);this._srv=new iA(h=>{if(this._connections>=this.maxConnections){h.destroy();return}++this._connections,h.once("close",()=>{--this._connections});let g;if(f){let y=`[${process.hrtime().join(".")}] `;g=_=>{f(`${y}${_}`)}}new js(h,r,l,u,g,this,t)}).on("error",h=>{this.emit("error",h)}).on("listening",()=>{this.emit("listening")}).on("close",()=>{this.emit("close")}),this._connections=0,this.maxConnections=1/0}injectSocket(t){this._srv.emit("connection",t)}listen(...t){return this._srv.listen(...t),this}address(){return this._srv.address()}getConnections(t){return this._srv.getConnections(t),this}close(t){return this._srv.close(t),this}ref(){return this._srv.ref(),this}unref(){return this._srv.unref(),this}};on.KEEPALIVE_CLIENT_INTERVAL=15e3;on.KEEPALIVE_CLIENT_COUNT_MAX=3;var js=class extends Oi{constructor(t,e,r,s,i,o,a){super();let c=0,f=!1,l=[],u,h,g,y=[];this._sock=t,this._chanMgr=new SA(this),this._debug=i,this.noMoreSessions=!1,this.authenticated=!1;function _(O){}this.on("error",_);let b=i?(O,x,w)=>{i(`Debug output from client: ${JSON.stringify(w)}`)}:void 0,C=typeof a.keepaliveInterval=="number"&&isFinite(a.keepaliveInterval)&&a.keepaliveInterval>0?a.keepaliveInterval:typeof on.KEEPALIVE_CLIENT_INTERVAL=="number"&&isFinite(on.KEEPALIVE_CLIENT_INTERVAL)&&on.KEEPALIVE_CLIENT_INTERVAL>0?on.KEEPALIVE_CLIENT_INTERVAL:-1,L=typeof a.keepaliveCountMax=="number"&&isFinite(a.keepaliveCountMax)&&a.keepaliveCountMax>=0?a.keepaliveCountMax:typeof on.KEEPALIVE_CLIENT_COUNT_MAX=="number"&&isFinite(on.KEEPALIVE_CLIENT_COUNT_MAX)&&on.KEEPALIVE_CLIENT_COUNT_MAX>=0?on.KEEPALIVE_CLIENT_COUNT_MAX:-1,F=0;C!==-1&&L!==-1&&(this.once("ready",()=>{let O=()=>{clearInterval(h)};this.on("close",O).on("end",O),h=setInterval(()=>{if(++F>L){clearInterval(h);let x=new Error("Keepalive timeout");x.level="client-timeout",this.emit("error",x),this.end()}else k.ping()},C)}),g=()=>{h&&h.refresh(),F=0});let k=this._protocol=new EA({server:!0,hostKeys:e,ident:r,offer:s,onPacket:g,greeting:a.greeting,banner:a.banner,onWrite:O=>{Gs(t)&&t.write(O)},onError:O=>{k._destruct||t.removeAllListeners("data"),this.emit("error",O);try{t.end()}catch{}},onHeader:O=>{this.removeListener("error",_);let x={ip:t.remoteAddress,family:t.remoteFamily,port:t.remotePort,header:O};if(!o.emit("connection",this,x)){k.disconnect(Yr.BY_APPLICATION),t.end();return}O.greeting&&this.emit("greeting",O.greeting)},onHandshakeComplete:O=>{++c>1&&this.emit("rekey"),this.emit("handshake",O)},debug:i,messageHandlers:{DEBUG:b,DISCONNECT:(O,x,w)=>{if(x!==Yr.BY_APPLICATION){w||(w=lA[x],w===void 0&&(w=`Unexpected disconnection reason: ${x}`));let I=new Error(w);I.code=x,this.emit("error",I)}t.end()},CHANNEL_OPEN:(O,x)=>{if(x.type==="session"&&this.noMoreSessions||!this.authenticated){let te=Gr.ADMINISTRATIVELY_PROHIBITED;return k.channelOpenFail(x.sender,te)}let w=-1,I,U=!1,R,re=()=>{U||(U=!0,I===void 0&&(w===-1?I=Gr.RESOURCE_SHORTAGE:I=Gr.CONNECT_FAILED),w!==-1&&this._chanMgr.remove(w),k.channelOpenFail(x.sender,I,""))},G=()=>(w=this._chanMgr.add(),w===-1&&(I=Gr.RESOURCE_SHORTAGE,i&&i("Automatic rejection of incoming channel open: no channels available")),w!==-1),Y=x.data;switch(x.type){case"session":if(Kt(this,"session")&&G()){R=()=>{if(U)return;U=!0;let te=new vn(this,x,w);return this._chanMgr.update(w,te),k.channelOpenConfirm(x.sender,w,Xn,Jn),te},this.emit("session",R,re);return}break;case"direct-tcpip":if(Kt(this,"tcpip")&&G()){R=()=>{if(U)return;U=!0;let te={type:void 0,incoming:{id:w,window:Xn,packetSize:Jn,state:"open"},outgoing:{id:x.sender,window:x.window,packetSize:x.packetSize,state:"open"}},ce=new zr(this,te,{server:!0});return this._chanMgr.update(w,ce),k.channelOpenConfirm(x.sender,w,Xn,Jn),ce},this.emit("tcpip",R,re,Y);return}break;case"direct-streamlocal@openssh.com":if(Kt(this,"openssh.streamlocal")&&G()){R=()=>{if(U)return;U=!0;let te={type:void 0,incoming:{id:w,window:Xn,packetSize:Jn,state:"open"},outgoing:{id:x.sender,window:x.window,packetSize:x.packetSize,state:"open"}},ce=new zr(this,te,{server:!0});return this._chanMgr.update(w,ce),k.channelOpenConfirm(x.sender,w,Xn,Jn),ce},this.emit("openssh.streamlocal",R,re,Y);return}break;default:I=Gr.UNKNOWN_CHANNEL_TYPE,i&&i(`Automatic rejection of unsupported incoming channel open type: ${x.type}`)}I===void 0&&(I=Gr.ADMINISTRATIVELY_PROHIBITED,i&&i(`Automatic rejection of unexpected incoming channel open for: ${x.type}`)),re()},CHANNEL_OPEN_CONFIRMATION:(O,x)=>{let w=this._chanMgr.get(x.recipient);if(typeof w!="function")return;let I={type:w.type,incoming:{id:x.recipient,window:Xn,packetSize:Jn,state:"open"},outgoing:{id:x.sender,window:x.window,packetSize:x.packetSize,state:"open"}},U=new zr(this,I,{server:!0});this._chanMgr.update(x.recipient,U),w(void 0,U)},CHANNEL_OPEN_FAILURE:(O,x,w,I)=>{let U=this._chanMgr.get(x);if(typeof U!="function")return;wA(this,x,{reason:w,description:I},U)},CHANNEL_DATA:(O,x,w)=>{let I=this._chanMgr.get(x);if(!(typeof I!="object"||I===null)&&!(I.constructor===vn&&(I=I._channel,!I))&&I.incoming.window!==0){if(I.incoming.window-=w.length,I.push(w)===!1){I._waitChanDrain=!0;return}I.incoming.window<=xA&&bA(I)}},CHANNEL_EXTENDED_DATA:(O,x,w,I)=>{},CHANNEL_WINDOW_ADJUST:(O,x,w)=>{let I=this._chanMgr.get(x);typeof I!="object"||I===null||I.constructor===vn&&(I=I._channel,!I)||(I.outgoing.window+=w,I._waitWindow&&(I._waitWindow=!1,I._chunk?I._write(I._chunk,null,I._chunkcb):I._chunkcb?I._chunkcb():I._chunkErr?I.stderr._write(I._chunkErr,null,I._chunkcbErr):I._chunkcbErr&&I._chunkcbErr()))},CHANNEL_SUCCESS:(O,x)=>{let w=this._chanMgr.get(x);typeof w!="object"||w===null||w.constructor===vn&&(w=w._channel,!w)||w._callbacks.length&&w._callbacks.shift()(!1)},CHANNEL_FAILURE:(O,x)=>{let w=this._chanMgr.get(x);typeof w!="object"||w===null||w.constructor===vn&&(w=w._channel,!w)||w._callbacks.length&&w._callbacks.shift()(!0)},CHANNEL_REQUEST:(O,x,w,I,U)=>{let R=this._chanMgr.get(x);if(typeof R!="object"||R===null)return;let re=!1,G,Y;if(R.constructor!==vn){I&&k.channelFailure(R.outgoing.id);return}if(I&&(w!=="shell"&&w!=="exec"&&w!=="subsystem"&&(G=()=>{re||R._ending||R._channel||(re=!0,k.channelSuccess(R._chanInfo.outgoing.id))}),Y=()=>{re||R._ending||R._channel||(re=!0,k.channelFailure(R._chanInfo.outgoing.id))}),R._ending){Y&&Y();return}switch(w){case"env":if(Kt(R,"env")){R.emit("env",G,Y,{key:U.name,val:U.value});return}break;case"pty-req":if(Kt(R,"pty")){R.emit("pty",G,Y,U);return}break;case"window-change":Kt(R,"window-change")?R.emit("window-change",G,Y,U):Y&&Y();break;case"x11-req":if(Kt(R,"x11")){R.emit("x11",G,Y,U);return}break;case"signal":if(Kt(R,"signal")){R.emit("signal",G,Y,{name:U});return}break;case"auth-agent-req@openssh.com":if(Kt(R,"auth-agent")){R.emit("auth-agent",G,Y);return}break;case"shell":if(Kt(R,"shell")){G=()=>{if(re||R._ending||R._channel)return;re=!0,I&&k.channelSuccess(R._chanInfo.outgoing.id);let te=new zr(this,R._chanInfo,{server:!0});return te.subtype=R.subtype=w,R._channel=te,te},R.emit("shell",G,Y);return}break;case"exec":if(Kt(R,"exec")){G=()=>{if(re||R._ending||R._channel)return;re=!0,I&&k.channelSuccess(R._chanInfo.outgoing.id);let te=new zr(this,R._chanInfo,{server:!0});return te.subtype=R.subtype=w,R._channel=te,te},R.emit("exec",G,Y,{command:U});return}break;case"subsystem":{let te=U==="sftp";if(G=()=>{if(re||R._ending||R._channel)return;re=!0,I&&k.channelSuccess(R._chanInfo.outgoing.id);let ce;return te?ce=new _A(this,R._chanInfo,{server:!0,debug:i}):(ce=new zr(this,R._chanInfo,{server:!0}),ce.subtype=R.subtype=`${w}:${U}`),R._channel=ce,ce},U==="sftp"){if(Kt(R,"sftp")){R.emit("sftp",G,Y);return}te=!1}if(Kt(R,"subsystem")){R.emit("subsystem",G,Y,{name:U});return}break}}i&&i(`Automatic rejection of incoming channel request: ${w}`),Y&&Y()},CHANNEL_EOF:(O,x)=>{let w=this._chanMgr.get(x);typeof w!="object"||w===null||w.constructor===vn&&(w._ending||(w._ending=!0,w.emit("eof"),w.emit("end")),w=w._channel,!w)||w.incoming.state==="open"&&(w.incoming.state="eof",w.readable&&w.push(null))},CHANNEL_CLOSE:(O,x)=>{let w=this._chanMgr.get(x);typeof w!="object"||w===null||w.constructor===vn&&(w._ending=!0,w.emit("close"),w=w._channel,!w)||IA(this,x,w)},SERVICE_REQUEST:(O,x)=>{if(c===0||f||this.authenticated||x!=="ssh-userauth"){k.disconnect(Yr.SERVICE_NOT_AVAILABLE),t.end();return}f=!0,k.serviceAccept(x)},USERAUTH_REQUEST:(O,x,w,I,U)=>{if(c===0||this.authenticated||u&&(u.username!==x||u.service!==w)||I!=="password"&&I!=="publickey"&&I!=="hostbased"&&I!=="keyboard-interactive"&&I!=="none"||l.length===CA){k.disconnect(Yr.PROTOCOL_ERROR),t.end();return}else if(w!=="ssh-connection"){k.disconnect(Yr.SERVICE_NOT_AVAILABLE),t.end();return}let R;switch(I){case"keyboard-interactive":R=new Ys(k,x,w,I,U,K);break;case"publickey":R=new lc(k,x,w,I,U,K);break;case"hostbased":R=new uc(k,x,w,I,U,K);break;case"password":if(u&&u instanceof zs&&u._changeCb){let re=u._changeCb;u._changeCb=void 0,re(U.newPassword);return}R=new zs(k,x,w,I,U,K);break;case"none":R=new Zn(k,x,w,I,K);break}if(u)if(u._initialResponse)u._multistep&&!u._finalResponse&&(u._cleanup&&u._cleanup(),u.emit("abort"));else return l.push(R);u=R,Kt(this,"authentication")?this.emit("authentication",u):u.reject()},USERAUTH_INFO_RESPONSE:(O,x)=>{u&&u instanceof Ys&&u._onInfoResponse(x)},GLOBAL_REQUEST:(O,x,w,I)=>{let U={type:null,buf:null};function R(re,G){U.type=re,U.buf=G,ee()}if(w&&y.push(U),(x==="tcpip-forward"||x==="cancel-tcpip-forward"||x==="no-more-sessions@openssh.com"||x==="streamlocal-forward@openssh.com"||x==="cancel-streamlocal-forward@openssh.com")&&Kt(this,"request")&&this.authenticated){let re,G;if(w){let Y=!1;re=te=>{if(Y)return;Y=!0;let ce;x==="tcpip-forward"&&I.bindPort===0&&typeof te=="number"&&(ce=Buffer.allocUnsafe(4),yA(ce,te,0)),R("SUCCESS",ce)},G=()=>{Y||(Y=!0,R("FAILURE"))}}if(x==="no-more-sessions@openssh.com"){this.noMoreSessions=!0,re&&re();return}this.emit("request",re,G,x,I)}else w&&R("FAILURE")}}});t.pause(),mA.then(()=>{k.start(),t.on("data",O=>{try{k.parse(O,0,O.length)}catch(x){this.emit("error",x);try{Gs(t)&&t.end()}catch{}}}),t.resume()}).catch(O=>{this.emit("error",O);try{Gs(t)&&t.end()}catch{}}),t.on("error",O=>{O.level="socket",this.emit("error",O)}).once("end",()=>{i&&i("Socket ended"),k.cleanup(),this.emit("end")}).once("close",()=>{i&&i("Socket closed"),k.cleanup(),this.emit("close");let O=new Error("No response from server");this._chanMgr.cleanup(O)});let K=(O,x,w,I)=>{u===O&&!this.authenticated&&(x?(u=void 0,this.authenticated=!0,k.authSuccess(),l=[],this.emit("ready")):(k.authFailure(w,I),l.length&&(u=l.pop(),Kt(this,"authentication")?this.emit("authentication",u):u.reject())))};function ee(){for(;y.length>0&&y[0].type;){let O=y.shift();O.type==="SUCCESS"&&k.requestSuccess(O.buf),O.type==="FAILURE"&&k.requestFailure()}}}end(){return this._sock&&Gs(this._sock)&&(this._protocol.disconnect(Yr.BY_APPLICATION),this._sock.end()),this}x11(t,e,r){return fc(this,"x11",{originAddr:t,originPort:e},r),this}forwardOut(t,e,r,s,i){return fc(this,"forwarded-tcpip",{boundAddr:t,boundPort:e,remoteAddr:r,remotePort:s},i),this}openssh_forwardOutStreamLocal(t,e){return fc(this,"forwarded-streamlocal@openssh.com",{socketPath:t},e),this}rekey(t){let e;try{this._protocol.rekey()}catch(r){e=r}typeof t=="function"&&(e?process.nextTick(t,e):this.once("rekey",t))}setNoDelay(t){return this._sock&&typeof this._sock.setNoDelay=="function"&&this._sock.setNoDelay(t),this}};function fc(n,t,e,r){let s=Xn,i=Jn;typeof e=="function"&&(r=e,e={});let o=(c,f)=>{r(c,f)};o.type=t;let a=n._chanMgr.add(o);if(a===-1){r(new Error("No free channels available"));return}switch(t){case"forwarded-tcpip":n._protocol.forwardedTcpip(a,s,i,e);break;case"x11":n._protocol.x11(a,s,i,e);break;case"forwarded-streamlocal@openssh.com":n._protocol.openssh_forwardedStreamLocal(a,s,i,e);break;default:throw new Error(`Unsupported channel type: ${t}`)}}function vA(n,t){return n-t}dc.exports=on;dc.exports.IncomingClient=js});var Bh=at((rS,kh)=>{"use strict";var{createCipheriv:kA,generateKeyPair:BA,generateKeyPairSync:RA,getCurves:NA,randomBytes:Ih}=require("crypto"),{Ber:Et}=li(),PA=No().pbkdf,{CIPHER_INFO:TA}=Kn(),LA=16,UA=16,DA=NA(),OA=new Map(Object.entries(TA));function Ch(n,t){if(typeof n!="string")throw new TypeError("Key type must be a string");let e={type:"spki",format:"der"},r={type:"pkcs8",format:"der"};switch(n.toLowerCase()){case"rsa":{if(typeof t!="object"||t===null)throw new TypeError("Missing options object for RSA key");let s=t.bits;if(!Number.isInteger(s))throw new TypeError("RSA bits must be an integer");if(s<=0||s>16384)throw new RangeError("RSA bits must be non-zero and <= 16384");return["rsa",{modulusLength:s,publicKeyEncoding:e,privateKeyEncoding:r}]}case"ecdsa":{if(typeof t!="object"||t===null)throw new TypeError("Missing options object for ECDSA key");if(!Number.isInteger(t.bits))throw new TypeError("ECDSA bits must be an integer");let s;switch(t.bits){case 256:s="prime256v1";break;case 384:s="secp384r1";break;case 521:s="secp521r1";break;default:throw new Error("ECDSA bits must be 256, 384, or 521")}if(!DA.includes(s))throw new Error("Unsupported ECDSA bits value");return["ec",{namedCurve:s,publicKeyEncoding:e,privateKeyEncoding:r}]}case"ed25519":return["ed25519",{publicKeyEncoding:e,privateKeyEncoding:r}];default:throw new Error(`Unsupported key type: ${n}`)}}function MA(n,t,e){switch(n){case"rsa":{let r=new Et.Reader(e);if(r.readSequence(),r.readInt()!==0)throw new Error("Unsupported version in RSA private key");if(r.readSequence(),r.readOID()!=="1.2.840.113549.1.1.1")throw new Error("Bad RSA private OID");if(r.readByte()!==Et.Null)throw new Error("Malformed RSA private key (expected null)");if(r.readByte()!==0)throw new Error("Malformed RSA private key (expected zero-length null)");if(r=new Et.Reader(r.readString(Et.OctetString,!0)),r.readSequence(),r.readInt()!==0)throw new Error("Unsupported version in RSA private key");let s=r.readString(Et.Integer,!0),i=r.readString(Et.Integer,!0),o=r.readString(Et.Integer,!0),a=r.readString(Et.Integer,!0),c=r.readString(Et.Integer,!0);r.readString(Et.Integer,!0),r.readString(Et.Integer,!0);let f=r.readString(Et.Integer,!0),l=Buffer.from("ssh-rsa"),u=Buffer.allocUnsafe(4+l.length+4+s.length+4+i.length+4+o.length+4+f.length+4+a.length+4+c.length),h=0;u.writeUInt32BE(l.length,h+=0),u.set(l,h+=4),u.writeUInt32BE(s.length,h+=l.length),u.set(s,h+=4),u.writeUInt32BE(i.length,h+=s.length),u.set(i,h+=4),u.writeUInt32BE(o.length,h+=i.length),u.set(o,h+=4),u.writeUInt32BE(f.length,h+=o.length),u.set(f,h+=4),u.writeUInt32BE(a.length,h+=f.length),u.set(a,h+=4),u.writeUInt32BE(c.length,h+=a.length),u.set(c,h+=4);let g=Buffer.allocUnsafe(4+l.length+4+i.length+4+s.length);return h=0,g.writeUInt32BE(l.length,h+=0),g.set(l,h+=4),g.writeUInt32BE(i.length,h+=l.length),g.set(i,h+=4),g.writeUInt32BE(s.length,h+=i.length),g.set(s,h+=4),{sshName:l.toString(),priv:u,pub:g}}case"ec":{let r=new Et.Reader(t);if(r.readSequence(),r.readSequence(),r.readOID()!=="1.2.840.10045.2.1")throw new Error("Bad ECDSA public OID");r.readOID();let s=r.readString(Et.BitString,!0);{let h=0;for(;h<s.length&&s[h]===0;++h);h>0&&(s=s.slice(h))}if(r=new Et.Reader(e),r.readSequence(),r.readInt()!==0)throw new Error("Unsupported version in ECDSA private key");if(r.readSequence(),r.readOID()!=="1.2.840.10045.2.1")throw new Error("Bad ECDSA private OID");let i=r.readOID(),o;switch(i){case"1.2.840.10045.3.1.7":o="nistp256";break;case"1.3.132.0.34":o="nistp384";break;case"1.3.132.0.35":o="nistp521";break;default:throw new Error("Unsupported curve in ECDSA private key")}if(r=new Et.Reader(r.readString(Et.OctetString,!0)),r.readSequence(),r.readInt()!==1)throw new Error("Unsupported version in ECDSA private key");let a=Buffer.concat([Buffer.from([0]),r.readString(Et.OctetString,!0)]),c=Buffer.from(`ecdsa-sha2-${o}`);o=Buffer.from(o);let f=Buffer.allocUnsafe(4+c.length+4+o.length+4+s.length+4+a.length),l=0;f.writeUInt32BE(c.length,l+=0),f.set(c,l+=4),f.writeUInt32BE(o.length,l+=c.length),f.set(o,l+=4),f.writeUInt32BE(s.length,l+=o.length),f.set(s,l+=4),f.writeUInt32BE(a.length,l+=s.length),f.set(a,l+=4);let u=Buffer.allocUnsafe(4+c.length+4+o.length+4+s.length);return l=0,u.writeUInt32BE(c.length,l+=0),u.set(c,l+=4),u.writeUInt32BE(o.length,l+=c.length),u.set(o,l+=4),u.writeUInt32BE(s.length,l+=o.length),u.set(s,l+=4),{sshName:c.toString(),priv:f,pub:u}}case"ed25519":{let r=new Et.Reader(t);if(r.readSequence(),r.readSequence(),r.readOID()!=="1.3.101.112")throw new Error("Bad ED25519 public OID");let s=r.readString(Et.BitString,!0);{let l=0;for(;l<s.length&&s[l]===0;++l);l>0&&(s=s.slice(l))}if(r=new Et.Reader(e),r.readSequence(),r.readInt()!==0)throw new Error("Unsupported version in ED25519 private key");if(r.readSequence(),r.readOID()!=="1.3.101.112")throw new Error("Bad ED25519 private OID");r=new Et.Reader(r.readString(Et.OctetString,!0));let i=r.readString(Et.OctetString,!0),o=Buffer.from("ssh-ed25519"),a=Buffer.allocUnsafe(4+o.length+4+s.length+4+(i.length+s.length)),c=0;a.writeUInt32BE(o.length,c+=0),a.set(o,c+=4),a.writeUInt32BE(s.length,c+=o.length),a.set(s,c+=4),a.writeUInt32BE(i.length+s.length,c+=s.length),a.set(i,c+=4),a.set(s,c+=i.length);let f=Buffer.allocUnsafe(4+o.length+4+s.length);return c=0,f.writeUInt32BE(o.length,c+=0),f.set(o,c+=4),f.writeUInt32BE(s.length,c+=o.length),f.set(s,c+=4),{sshName:o.toString(),priv:a,pub:f}}}}function vh(n,t,e,r){let s="new",i,o="";if(typeof r=="object"&&r!==null&&(typeof r.comment=="string"&&r.comment&&(o=r.comment),typeof r.format=="string"&&r.format&&(s=r.format),r.passphrase)){let a;if(typeof r.passphrase=="string")a=Buffer.from(r.passphrase);else if(Buffer.isBuffer(r.passphrase))a=r.passphrase;else throw new Error("Invalid passphrase");if(r.cipher===void 0)throw new Error("Missing cipher name");let c=OA.get(r.cipher);if(c===void 0)throw new Error("Invalid cipher name");if(s==="new"){let f=UA;if(r.rounds!==void 0){if(!Number.isInteger(r.rounds))throw new TypeError("rounds must be an integer");r.rounds>0&&(f=r.rounds)}let l=Buffer.allocUnsafe(c.keyLen+c.ivLen),u=Ih(LA);if(PA(a,a.length,u,u.length,l,l.length,f)!==0)return new Error("Failed to generate information to encrypt key");let g=Buffer.allocUnsafe(4+u.length+4);{let y=0;g.writeUInt32BE(u.length,y+=0),g.set(u,y+=4),g.writeUInt32BE(f,y+=u.length)}i={cipher:c,cipherName:r.cipher,kdfName:"bcrypt",kdfOptions:g,key:l.slice(0,c.keyLen),iv:l.slice(c.keyLen)}}}switch(s){case"new":{let a=`-----BEGIN OPENSSH PRIVATE KEY-----
|
|
15
|
-
`,c,f=Buffer.from(i?i.cipherName:"none"),l=Buffer.from(i?i.kdfName:"none"),u=i?i.kdfOptions:Buffer.alloc(0),h=i?i.cipher.blockLen:8,g=
|
|
14
|
+
${e}`}};var qg=2**32,jf=(()=>{try{return new Function("return 2n ** 32n")()}catch{}})();yi.ERR_OUT_OF_RANGE=class Jf extends RangeError{constructor(t,e,r,s){super(),Error.captureStackTrace(this,Jf),ys(e,'Missing "range" argument');let i=s?t:`The value of "${t}" is out of range.`,o;Number.isInteger(r)&&Math.abs(r)>qg?o=Yf(String(r)):typeof r=="bigint"?(o=String(r),(r>jf||r<-jf)&&(o=Yf(o)),o+="n"):o=Wg(r),i+=` It must be ${e}. Received ${o}`,this.message=i}};var bs=class n extends TypeError{constructor(t,e,r){super(),Error.captureStackTrace(this,n),ys(typeof t=="string","'name' must be a string");let s;typeof e=="string"&&e.startsWith("not ")?(s="must not be",e=e.replace(/^not /,"")):s="must be";let i;if(t.endsWith(" argument"))i=`The ${t} ${s} ${zf(e,"type")}`;else{let o=t.includes(".")?"property":"argument";i=`The "${t}" ${o} ${s} ${zf(e,"type")}`}i+=`. Received type ${typeof r}`,this.message=i}};yi.ERR_INVALID_ARG_TYPE=bs;yi.validateNumber=function(t,e){if(typeof t!="number")throw new bs(e,"number",t)}});var bi=at((CE,dl)=>{"use strict";var Kg=require("events"),Gn=require("fs"),{constants:Jt}=Gn,{Readable:sl,Writable:xa}=require("stream"),{inherits:ol,types:{isDate:ma}}=require("util"),Vg=Buffer[Symbol.species],{bufferCopy:Vn,bufferSlice:Or,makeBufferParser:Gg,writeUInt32BE:q}=dn(),Un={SIZE:1,UIDGID:2,PERMISSIONS:4,ACMODTIME:8,EXTENDED:2147483648},Re=Buffer.alloc(28),et={OK:0,EOF:1,NO_SUCH_FILE:2,PERMISSION_DENIED:3,FAILURE:4,BAD_MESSAGE:5,NO_CONNECTION:6,CONNECTION_LOST:7,OP_UNSUPPORTED:8},Yg=new Map(Object.values(et).map(n=>[n,1])),zg={[et.OK]:"No error",[et.EOF]:"End of file",[et.NO_SUCH_FILE]:"No such file or directory",[et.PERMISSION_DENIED]:"Permission denied",[et.FAILURE]:"Failure",[et.BAD_MESSAGE]:"Bad message",[et.NO_CONNECTION]:"No connection",[et.CONNECTION_LOST]:"Connection lost",[et.OP_UNSUPPORTED]:"Operation unsupported"},ke={INIT:1,OPEN:3,CLOSE:4,READ:5,WRITE:6,LSTAT:7,FSTAT:8,SETSTAT:9,FSETSTAT:10,OPENDIR:11,READDIR:12,REMOVE:13,MKDIR:14,RMDIR:15,REALPATH:16,STAT:17,RENAME:18,READLINK:19,SYMLINK:20,EXTENDED:200},Zt={VERSION:2,STATUS:101,HANDLE:102,DATA:103,NAME:104,ATTRS:105,EXTENDED:201},Ie={READ:1,WRITE:2,APPEND:4,CREAT:8,TRUNC:16,EXCL:32},el=2*1024,ft=2**32-1,jg=Buffer.from([0,0,0,5,ke.INIT,0,0,0,3]),Xg=Buffer.from([0,0,0,5,Zt.VERSION,0,0,0,3]),Jg=/^SSH-2.0-(?:OpenSSH|dropbear)/,pa=256*1024,M=Gg(),Zg={readable:!1,writable:!1,push:n=>{},once:()=>{},on:()=>{},emit:()=>{},end:()=>{}};function al(){}var Aa=class extends Kg{constructor(t,e,r){super(),(typeof r!="object"||!r)&&(r={});let s=t._protocol._remoteIdentRaw;this.server=!!r.server,this._debug=typeof r.debug=="function"?r.debug:void 0,this._isOpenSSH=s&&Jg.test(s),this._version=-1,this._extensions={},this._biOpt=r.biOpt,this._pktLenBytes=0,this._pktLen=0,this._pktPos=0,this._pktType=0,this._pktData=void 0,this._writeReqid=-1,this._requests={},this._maxInPktLen=pa,this._maxOutPktLen=34e3,this._maxReadLen=(this._isOpenSSH?pa:34e3)-el,this._maxWriteLen=(this._isOpenSSH?pa:34e3)-el,this.maxOpenHandles=void 0,this._client=t,this._protocol=t._protocol,this._callbacks=[],this._hasX11=!1,this._exit={code:void 0,signal:void 0,dump:void 0,desc:void 0},this._waitWindow=!1,this._chunkcb=void 0,this._buffer=[],this.type=e.type,this.subtype=void 0,this.incoming=e.incoming,this.outgoing=e.outgoing,this.stderr=Zg,this.readable=!0}push(t){if(t===null){if(ul(this),!this.readable)return;this.readable=!1,this.emit("end");return}let e=0;for(;e<t.length;){if(this._pktLenBytes<4){let o=Math.min(4-this._pktLenBytes,t.length-e);for(this._pktLenBytes+=o;o--;)this._pktLen=(this._pktLen<<8)+t[e++];if(this._pktLenBytes<4)return;if(this._pktLen===0)return it(this,"Invalid packet length");if(this._pktLen>this._maxInPktLen){let a=this._maxInPktLen;return it(this,`Packet length ${this._pktLen} exceeds max length of ${a}`)}if(e>=t.length)return}if(this._pktPos<this._pktLen){let o=Math.min(this._pktLen-this._pktPos,t.length-e);if(e!==0||o!==t.length?o===this._pktLen?this._pkt=new Vg(t.buffer,t.byteOffset+e,o):(this._pkt||(this._pkt=Buffer.allocUnsafe(this._pktLen)),this._pkt.set(new Uint8Array(t.buffer,t.byteOffset+e,o),this._pktPos)):o===this._pktLen?this._pkt=t:(this._pkt||(this._pkt=Buffer.allocUnsafe(this._pktLen)),this._pkt.set(t,this._pktPos)),e+=o,this._pktPos+=o,this._pktPos<this._pktLen)return}let r=this._pkt[0],s=this._pkt;this._pktLen=0,this._pktLenBytes=0,this._pkt=void 0,this._pktPos=0;let i=this.server?i0[r]:r0[r];if(!i)return it(this,`Unknown packet type ${r}`);if(this._version===-1){if(this.server){if(r!==ke.INIT)return it(this,`Expected INIT packet, got ${r}`)}else if(r!==Zt.VERSION)return it(this,`Expected VERSION packet, got ${r}`)}if(i(this,s)===!1)return}}end(){this.destroy()}destroy(){(this.outgoing.state==="open"||this.outgoing.state==="eof")&&(this.outgoing.state="closing",this._protocol.channelClose(this.outgoing.id))}_init(){this._init=al,this.server||Xe(this,jg)}createReadStream(t,e){if(this.server)throw new Error("Client-only method called in server mode");return new Dn(this,t,e)}createWriteStream(t,e){if(this.server)throw new Error("Client-only method called in server mode");return new un(this,t,e)}open(t,e,r,s){if(this.server)throw new Error("Client-only method called in server mode");typeof r=="function"&&(s=r,r=void 0);let i=typeof e=="number"?e:fl(e);if(i===null)throw new Error(`Unknown flags string: ${e}`);let o=0,a=0;(typeof r=="string"||typeof r=="number")&&(r={mode:r}),typeof r=="object"&&r!==null&&(r=cr(r),o=r.flags,a=r.nb);let c=Buffer.byteLength(t),f=9,l=Buffer.allocUnsafe(13+c+4+4+a);q(l,l.length-4,0),l[4]=ke.OPEN;let u=this._writeReqid=this._writeReqid+1&ft;q(l,u,5),q(l,c,f),l.utf8Write(t,f+=4,c),q(l,i,f+=c),q(l,o,f+=4),a&&(f+=4,a===Re.length?l.set(Re,f):Vn(Re,l,0,a,f),f+=a),this._requests[u]={cb:s};let h=Xe(this,l);this._debug&&this._debug(`SFTP: Outbound: ${h?"Buffered":"Sending"} OPEN`)}close(t,e){if(this.server)throw new Error("Client-only method called in server mode");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");let r=t.length,s=9,i=Buffer.allocUnsafe(13+r);q(i,i.length-4,0),i[4]=ke.CLOSE;let o=this._writeReqid=this._writeReqid+1&ft;q(i,o,5),q(i,r,s),i.set(t,s+=4),this._requests[o]={cb:e};let a=Xe(this,i);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} CLOSE`)}read(t,e,r,s,i,o){if(this.server)throw new Error("Client-only method called in server mode");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");if(!Buffer.isBuffer(e))throw new Error("buffer is not a Buffer");if(r>=e.length)throw new Error("offset is out of bounds");if(r+s>e.length)throw new Error("length extends beyond buffer");if(i===null)throw new Error("null position currently unsupported");cl(this,t,e,r,s,i,o)}readData(t,e,r,s,i,o){this.read(t,e,r,s,i,o)}write(t,e,r,s,i,o){if(this.server)throw new Error("Client-only method called in server mode");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");if(!Buffer.isBuffer(e))throw new Error("buffer is not a Buffer");if(r>e.length)throw new Error("offset is out of bounds");if(r+s>e.length)throw new Error("length extends beyond buffer");if(i===null)throw new Error("null position currently unsupported");if(!s){o&&process.nextTick(o,void 0,0);return}let a=this._maxWriteLen,c=Math.max(s-a,0),f=i;c&&(s=a);let l=t.length,u=9,h=Buffer.allocUnsafe(13+l+8+4+s);q(h,h.length-4,0),h[4]=ke.WRITE;let g=this._writeReqid=this._writeReqid+1&ft;q(h,g,5),q(h,l,u),h.set(t,u+=4),u+=l;for(let _=7;_>=0;--_)h[u+_]=i&255,i/=256;q(h,s,u+=8),Vn(e,h,r,r+s,u+=4),this._requests[g]={cb:_=>{_?typeof o=="function"&&o(_):c?this.write(t,e,r+s,c,f+s,o):typeof o=="function"&&o(void 0,r+s)}};let y=Xe(this,h);if(this._debug){let _=y?"Sent":"Buffered";this._debug(`SFTP: Outbound: ${_} WRITE (id:${g})`)}}writeData(t,e,r,s,i,o){this.write(t,e,r,s,i,o)}fastGet(t,e,r,s){if(this.server)throw new Error("Client-only method called in server mode");tl(this,Gn,t,e,r,s)}fastPut(t,e,r,s){if(this.server)throw new Error("Client-only method called in server mode");tl(Gn,this,t,e,r,s)}readFile(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");let s;if(typeof r=="function"?s=r:typeof e=="function"&&(s=e,e=void 0),typeof e=="string")e={encoding:e,flag:"r"};else if(!e)e={encoding:null,flag:"r"};else if(typeof e!="object")throw new TypeError("Bad arguments");let i=e.encoding;if(i&&!Buffer.isEncoding(i))throw new Error(`Unknown encoding: ${i}`);let o,a,c,f=0,l,u=0,h=e.flag||"r",g=()=>{o===0?(a=Buffer.allocUnsafe(8192),this.read(l,a,0,8192,u,y)):this.read(l,a,f,o-f,u,y)},y=(b,C)=>{let L;if(b){if(L=b.code===et.EOF,!L)return this.close(l,()=>s&&s(b))}else L=!1;if(L||o===0&&C===0)return _();u+=C,f+=C,o!==0?f===o?_():g():(c.push(Or(a,0,C)),g())};y._wantEOFError=!0;let _=()=>{this.close(l,b=>(o===0?a=Buffer.concat(c,f):f<o&&(a=Or(a,0,f)),i&&(a=a.toString(i)),s&&s(b,a)))};this.open(t,h,438,(b,C)=>{if(b)return s&&s(b);l=C;let L=(F,k)=>{if(F){this.stat(t,(K,ee)=>{if(K)return this.close(l,()=>{s&&s(F)});L(null,ee)});return}if(o=k.size||0,o===0)return c=[],g();a=Buffer.allocUnsafe(o),g()};this.fstat(l,L)})}writeFile(t,e,r,s){if(this.server)throw new Error("Client-only method called in server mode");let i;if(typeof s=="function"?i=s:typeof r=="function"&&(i=r,r=void 0),typeof r=="string")r={encoding:r,mode:438,flag:"w"};else if(!r)r={encoding:"utf8",mode:438,flag:"w"};else if(typeof r!="object")throw new TypeError("Bad arguments");if(r.encoding&&!Buffer.isEncoding(r.encoding))throw new Error(`Unknown encoding: ${r.encoding}`);let o=r.flag||"w";this.open(t,o,r.mode,(a,c)=>{if(a)i&&i(a);else{let f=Buffer.isBuffer(e)?e:Buffer.from(""+e,r.encoding||"utf8"),l=/a/.test(o)?null:0;if(l===null){let u=(h,g)=>{if(h){this.stat(t,(y,_)=>{if(y)return this.close(c,()=>{i&&i(h)});u(null,_)});return}Ea(this,c,f,0,f.length,g.size,i)};this.fstat(c,u);return}Ea(this,c,f,0,f.length,l,i)}})}appendFile(t,e,r,s){if(this.server)throw new Error("Client-only method called in server mode");let i;if(typeof s=="function"?i=s:typeof r=="function"&&(i=r,r=void 0),typeof r=="string")r={encoding:r,mode:438,flag:"a"};else if(!r)r={encoding:"utf8",mode:438,flag:"a"};else if(typeof r!="object")throw new TypeError("Bad arguments");r.flag||(r=Object.assign({flag:"a"},r)),this.writeFile(t,e,r,i)}exists(t,e){if(this.server)throw new Error("Client-only method called in server mode");this.stat(t,r=>{e&&e(!r)})}unlink(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),s=9,i=Buffer.allocUnsafe(13+r);q(i,i.length-4,0),i[4]=ke.REMOVE;let o=this._writeReqid=this._writeReqid+1&ft;q(i,o,5),q(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:e};let a=Xe(this,i);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} REMOVE`)}rename(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");let s=Buffer.byteLength(t),i=Buffer.byteLength(e),o=9,a=Buffer.allocUnsafe(13+s+4+i);q(a,a.length-4,0),a[4]=ke.RENAME;let c=this._writeReqid=this._writeReqid+1&ft;q(a,c,5),q(a,s,o),a.utf8Write(t,o+=4,s),q(a,i,o+=s),a.utf8Write(e,o+=4,i),this._requests[c]={cb:r};let f=Xe(this,a);this._debug&&this._debug(`SFTP: Outbound: ${f?"Buffered":"Sending"} RENAME`)}mkdir(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");let s=0,i=0;typeof e=="function"&&(r=e,e=void 0),typeof e=="object"&&e!==null&&(e=cr(e),s=e.flags,i=e.nb);let o=Buffer.byteLength(t),a=9,c=Buffer.allocUnsafe(13+o+4+i);q(c,c.length-4,0),c[4]=ke.MKDIR;let f=this._writeReqid=this._writeReqid+1&ft;q(c,f,5),q(c,o,a),c.utf8Write(t,a+=4,o),q(c,s,a+=o),i&&(a+=4,i===Re.length?c.set(Re,a):Vn(Re,c,0,i,a),a+=i),this._requests[f]={cb:r};let l=Xe(this,c);this._debug&&this._debug(`SFTP: Outbound: ${l?"Buffered":"Sending"} MKDIR`)}rmdir(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),s=9,i=Buffer.allocUnsafe(13+r);q(i,i.length-4,0),i[4]=ke.RMDIR;let o=this._writeReqid=this._writeReqid+1&ft;q(i,o,5),q(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:e};let a=Xe(this,i);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} RMDIR`)}readdir(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");typeof e=="function"&&(r=e,e={}),(typeof e!="object"||e===null)&&(e={});let s=!(e&&e.full);if(!Buffer.isBuffer(t)&&typeof t!="string")throw new Error("missing directory handle or path");if(typeof t=="string"){let l=[],u=0,h=(g,y)=>{if(g)return r(g);this.readdir(y,e,(_,b)=>{let C=_&&_.code===et.EOF;if(_&&!C)return this.close(y,()=>r(_));if(C)return this.close(y,L=>{if(L)return r(L);r(void 0,l)});for(let L=0;L<b.length;++L,++u)l[u]=b[L];h(void 0,y)})};return this.opendir(t,h)}let i=t.length,o=9,a=Buffer.allocUnsafe(13+i);q(a,a.length-4,0),a[4]=ke.READDIR;let c=this._writeReqid=this._writeReqid+1&ft;q(a,c,5),q(a,i,o),a.set(t,o+=4),this._requests[c]={cb:s?(l,u)=>{if(typeof r=="function"){if(l)return r(l);for(let h=u.length-1;h>=0;--h)(u[h].filename==="."||u[h].filename==="..")&&u.splice(h,1);r(void 0,u)}}:r};let f=Xe(this,a);this._debug&&this._debug(`SFTP: Outbound: ${f?"Buffered":"Sending"} READDIR`)}fstat(t,e){if(this.server)throw new Error("Client-only method called in server mode");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");let r=t.length,s=9,i=Buffer.allocUnsafe(13+r);q(i,i.length-4,0),i[4]=ke.FSTAT;let o=this._writeReqid=this._writeReqid+1&ft;q(i,o,5),q(i,r,s),i.set(t,s+=4),this._requests[o]={cb:e};let a=Xe(this,i);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} FSTAT`)}stat(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),s=9,i=Buffer.allocUnsafe(13+r);q(i,i.length-4,0),i[4]=ke.STAT;let o=this._writeReqid=this._writeReqid+1&ft;q(i,o,5),q(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:e};let a=Xe(this,i);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} STAT`)}lstat(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),s=9,i=Buffer.allocUnsafe(13+r);q(i,i.length-4,0),i[4]=ke.LSTAT;let o=this._writeReqid=this._writeReqid+1&ft;q(i,o,5),q(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:e};let a=Xe(this,i);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} LSTAT`)}opendir(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),s=9,i=Buffer.allocUnsafe(13+r);q(i,i.length-4,0),i[4]=ke.OPENDIR;let o=this._writeReqid=this._writeReqid+1&ft;q(i,o,5),q(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:e};let a=Xe(this,i);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} OPENDIR`)}setstat(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");let s=0,i=0;typeof e=="object"&&e!==null?(e=cr(e),s=e.flags,i=e.nb):typeof e=="function"&&(r=e);let o=Buffer.byteLength(t),a=9,c=Buffer.allocUnsafe(13+o+4+i);q(c,c.length-4,0),c[4]=ke.SETSTAT;let f=this._writeReqid=this._writeReqid+1&ft;q(c,f,5),q(c,o,a),c.utf8Write(t,a+=4,o),q(c,s,a+=o),i&&(a+=4,i===Re.length?c.set(Re,a):Vn(Re,c,0,i,a),a+=i),this._requests[f]={cb:r};let l=Xe(this,c);this._debug&&this._debug(`SFTP: Outbound: ${l?"Buffered":"Sending"} SETSTAT`)}fsetstat(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");let s=0,i=0;typeof e=="object"&&e!==null?(e=cr(e),s=e.flags,i=e.nb):typeof e=="function"&&(r=e);let o=t.length,a=9,c=Buffer.allocUnsafe(13+o+4+i);q(c,c.length-4,0),c[4]=ke.FSETSTAT;let f=this._writeReqid=this._writeReqid+1&ft;q(c,f,5),q(c,o,a),c.set(t,a+=4),q(c,s,a+=o),i&&(a+=4,i===Re.length?c.set(Re,a):Vn(Re,c,0,i,a),a+=i),this._requests[f]={cb:r};let l=Xe(this,c);this._debug&&this._debug(`SFTP: Outbound: ${l?"Buffered":"Sending"} FSETSTAT`)}futimes(t,e,r,s){return this.fsetstat(t,{atime:Ur(e),mtime:Ur(r)},s)}utimes(t,e,r,s){return this.setstat(t,{atime:Ur(e),mtime:Ur(r)},s)}fchown(t,e,r,s){return this.fsetstat(t,{uid:e,gid:r},s)}chown(t,e,r,s){return this.setstat(t,{uid:e,gid:r},s)}fchmod(t,e,r){return this.fsetstat(t,{mode:e},r)}chmod(t,e,r){return this.setstat(t,{mode:e},r)}readlink(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),s=9,i=Buffer.allocUnsafe(13+r);q(i,i.length-4,0),i[4]=ke.READLINK;let o=this._writeReqid=this._writeReqid+1&ft;q(i,o,5),q(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:(c,f)=>{if(typeof e=="function"){if(c)return e(c);if(!f||!f.length)return e(new Error("Response missing link info"));e(void 0,f[0].filename)}}};let a=Xe(this,i);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} READLINK`)}symlink(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");let s=Buffer.byteLength(e),i=Buffer.byteLength(t),o=9,a=Buffer.allocUnsafe(13+s+4+i);q(a,a.length-4,0),a[4]=ke.SYMLINK;let c=this._writeReqid=this._writeReqid+1&ft;q(a,c,5),this._isOpenSSH?(q(a,i,o),a.utf8Write(t,o+=4,i),q(a,s,o+=i),a.utf8Write(e,o+=4,s)):(q(a,s,o),a.utf8Write(e,o+=4,s),q(a,i,o+=s),a.utf8Write(t,o+=4,i)),this._requests[c]={cb:r};let f=Xe(this,a);this._debug&&this._debug(`SFTP: Outbound: ${f?"Buffered":"Sending"} SYMLINK`)}realpath(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),s=9,i=Buffer.allocUnsafe(13+r);q(i,i.length-4,0),i[4]=ke.REALPATH;let o=this._writeReqid=this._writeReqid+1&ft;q(i,o,5),q(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:(c,f)=>{if(typeof e=="function"){if(c)return e(c);if(!f||!f.length)return e(new Error("Response missing path info"));e(void 0,f[0].filename)}}};let a=Xe(this,i);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} REALPATH`)}ext_openssh_rename(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");let s=this._extensions["posix-rename@openssh.com"];if(!s||s!=="1")throw new Error("Server does not support this extended request");let i=Buffer.byteLength(t),o=Buffer.byteLength(e),a=9,c=Buffer.allocUnsafe(41+i+4+o);q(c,c.length-4,0),c[4]=ke.EXTENDED;let f=this._writeReqid=this._writeReqid+1&ft;q(c,f,5),q(c,24,a),c.utf8Write("posix-rename@openssh.com",a+=4,24),q(c,i,a+=24),c.utf8Write(t,a+=4,i),q(c,o,a+=i),c.utf8Write(e,a+=4,o),this._requests[f]={cb:r};let l=Xe(this,c);if(this._debug){let u=l?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${u} posix-rename@openssh.com`)}}ext_openssh_statvfs(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=this._extensions["statvfs@openssh.com"];if(!r||r!=="2")throw new Error("Server does not support this extended request");let s=Buffer.byteLength(t),i=9,o=Buffer.allocUnsafe(36+s);q(o,o.length-4,0),o[4]=ke.EXTENDED;let a=this._writeReqid=this._writeReqid+1&ft;q(o,a,5),q(o,19,i),o.utf8Write("statvfs@openssh.com",i+=4,19),q(o,s,i+=19),o.utf8Write(t,i+=4,s),this._requests[a]={extended:"statvfs@openssh.com",cb:e};let c=Xe(this,o);if(this._debug){let f=c?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${f} statvfs@openssh.com`)}}ext_openssh_fstatvfs(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=this._extensions["fstatvfs@openssh.com"];if(!r||r!=="2")throw new Error("Server does not support this extended request");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");let s=t.length,i=9,o=Buffer.allocUnsafe(37+s);q(o,o.length-4,0),o[4]=ke.EXTENDED;let a=this._writeReqid=this._writeReqid+1&ft;q(o,a,5),q(o,20,i),o.utf8Write("fstatvfs@openssh.com",i+=4,20),q(o,s,i+=20),o.set(t,i+=4),this._requests[a]={extended:"fstatvfs@openssh.com",cb:e};let c=Xe(this,o);if(this._debug){let f=c?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${f} fstatvfs@openssh.com`)}}ext_openssh_hardlink(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["hardlink@openssh.com"]!=="1")throw new Error("Server does not support this extended request");let i=Buffer.byteLength(t),o=Buffer.byteLength(e),a=9,c=Buffer.allocUnsafe(37+i+4+o);q(c,c.length-4,0),c[4]=ke.EXTENDED;let f=this._writeReqid=this._writeReqid+1&ft;q(c,f,5),q(c,20,a),c.utf8Write("hardlink@openssh.com",a+=4,20),q(c,i,a+=20),c.utf8Write(t,a+=4,i),q(c,o,a+=i),c.utf8Write(e,a+=4,o),this._requests[f]={cb:r};let l=Xe(this,c);if(this._debug){let u=l?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${u} hardlink@openssh.com`)}}ext_openssh_fsync(t,e){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["fsync@openssh.com"]!=="1")throw new Error("Server does not support this extended request");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");let s=t.length,i=9,o=Buffer.allocUnsafe(34+s);q(o,o.length-4,0),o[4]=ke.EXTENDED;let a=this._writeReqid=this._writeReqid+1&ft;q(o,a,5),q(o,17,i),o.utf8Write("fsync@openssh.com",i+=4,17),q(o,s,i+=17),o.set(t,i+=4),this._requests[a]={cb:e};let c=Xe(this,o);this._debug&&this._debug(`SFTP: Outbound: ${c?"Buffered":"Sending"} fsync@openssh.com`)}ext_openssh_lsetstat(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["lsetstat@openssh.com"]!=="1")throw new Error("Server does not support this extended request");let i=0,o=0;typeof e=="object"&&e!==null?(e=cr(e),i=e.flags,o=e.nb):typeof e=="function"&&(r=e);let a=Buffer.byteLength(t),c=9,f=Buffer.allocUnsafe(37+a+4+o);q(f,f.length-4,0),f[4]=ke.EXTENDED;let l=this._writeReqid=this._writeReqid+1&ft;q(f,l,5),q(f,20,c),f.utf8Write("lsetstat@openssh.com",c+=4,20),q(f,a,c+=20),f.utf8Write(t,c+=4,a),q(f,i,c+=a),o&&(c+=4,o===Re.length?f.set(Re,c):Vn(Re,f,0,o,c),c+=o),this._requests[l]={cb:r};let u=Xe(this,f);if(this._debug){let h=u?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${h} lsetstat@openssh.com`)}}ext_openssh_expandPath(t,e){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["expand-path@openssh.com"]!=="1")throw new Error("Server does not support this extended request");let s=Buffer.byteLength(t),i=9,o=Buffer.allocUnsafe(40+s);q(o,o.length-4,0),o[4]=ke.EXTENDED;let a=this._writeReqid=this._writeReqid+1&ft;q(o,a,5),q(o,23,i),o.utf8Write("expand-path@openssh.com",i+=4,23),q(o,s,i+=20),o.utf8Write(t,i+=4,s),this._requests[a]={cb:(f,l)=>{if(typeof e=="function"){if(f)return e(f);if(!l||!l.length)return e(new Error("Response missing expanded path"));e(void 0,l[0].filename)}}};let c=Xe(this,o);if(this._debug){let f=c?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${f} expand-path@openssh.com`)}}ext_copy_data(t,e,r,s,i,o){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["copy-data"]!=="1")throw new Error("Server does not support this extended request");if(!Buffer.isBuffer(t))throw new Error("Source handle is not a Buffer");if(!Buffer.isBuffer(s))throw new Error("Destination handle is not a Buffer");let c=0,f=Buffer.allocUnsafe(26+t.length+8+8+4+s.length+8);q(f,f.length-4,c),c+=4,f[c]=ke.EXTENDED,++c;let l=this._writeReqid=this._writeReqid+1&ft;q(f,l,c),c+=4,q(f,9,c),c+=4,f.utf8Write("copy-data",c,9),c+=9,q(f,t.length,c),c+=4,f.set(t,c),c+=t.length;for(let h=7;h>=0;--h)f[c+h]=e&255,e/=256;c+=8;for(let h=7;h>=0;--h)f[c+h]=r&255,r/=256;c+=8,q(f,s.length,c),c+=4,f.set(s,c),c+=s.length;for(let h=7;h>=0;--h)f[c+h]=i&255,i/=256;this._requests[l]={cb:o};let u=Xe(this,f);if(this._debug){let h=u?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${h} copy-data`)}}ext_home_dir(t,e){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["home-directory"]!=="1")throw new Error("Server does not support this extended request");if(typeof t!="string")throw new TypeError("username is not a string");let s=0,i=Buffer.byteLength(t),o=Buffer.allocUnsafe(31+i);q(o,o.length-4,s),s+=4,o[s]=ke.EXTENDED,++s;let a=this._writeReqid=this._writeReqid+1&ft;q(o,a,s),s+=4,q(o,14,s),s+=4,o.utf8Write("home-directory",s,14),s+=14,q(o,i,s),s+=4,o.utf8Write(t,s,i),s+=i,this._requests[a]={cb:(f,l)=>{if(typeof e=="function"){if(f)return e(f);if(!l||!l.length)return e(new Error("Response missing home directory"));e(void 0,l[0].filename)}}};let c=Xe(this,o);if(this._debug){let f=c?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${f} home-directory`)}}ext_users_groups(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["users-groups-by-id@openssh.com"]!=="1")throw new Error("Server does not support this extended request");if(!Array.isArray(t))throw new TypeError("uids is not an array");for(let f of t)if(!Number.isInteger(f)||f<0||f>2**32-1)throw new Error("uid values must all be 32-bit unsigned integers");if(!Array.isArray(e))throw new TypeError("gids is not an array");for(let f of e)if(!Number.isInteger(f)||f<0||f>2**32-1)throw new Error("gid values must all be 32-bit unsigned integers");let i=0,o=Buffer.allocUnsafe(47+4*t.length+4+4*e.length);q(o,o.length-4,i),i+=4,o[i]=ke.EXTENDED,++i;let a=this._writeReqid=this._writeReqid+1&ft;q(o,a,i),i+=4,q(o,30,i),i+=4,o.utf8Write("users-groups-by-id@openssh.com",i,30),i+=30,q(o,4*t.length,i),i+=4;for(let f of t)q(o,f,i),i+=4;q(o,4*e.length,i),i+=4;for(let f of e)q(o,f,i),i+=4;this._requests[a]={extended:"users-groups-by-id@openssh.com",cb:r};let c=Xe(this,o);if(this._debug){let f=c?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${f} users-groups-by-id@openssh.com`)}}handle(t,e){if(!this.server)throw new Error("Server-only method called in client mode");if(!Buffer.isBuffer(e))throw new Error("handle is not a Buffer");let r=e.length;if(r>256)throw new Error("handle too large (> 256 bytes)");let s=9,i=Buffer.allocUnsafe(13+r);q(i,i.length-4,0),i[4]=Zt.HANDLE,q(i,t,5),q(i,r,s),r&&i.set(e,s+=4);let o=Xe(this,i);this._debug&&this._debug(`SFTP: Outbound: ${o?"Buffered":"Sending"} HANDLE`)}status(t,e,r){if(!this.server)throw new Error("Server-only method called in client mode");if(!Yg.has(e))throw new Error(`Bad status code: ${e}`);r||(r="");let s=Buffer.byteLength(r),i=9,o=Buffer.allocUnsafe(17+s+4);q(o,o.length-4,0),o[4]=Zt.STATUS,q(o,t,5),q(o,e,i),q(o,s,i+=4),i+=4,s&&(o.utf8Write(r,i,s),i+=s),q(o,0,i);let a=Xe(this,o);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} STATUS`)}data(t,e,r){if(!this.server)throw new Error("Server-only method called in client mode");let s=Buffer.isBuffer(e);if(!s&&typeof e!="string")throw new Error("data is not a Buffer or string");let i;!s&&!r&&(r=void 0,i=!0);let o=s?e.length:Buffer.byteLength(e,r),a=9,c=Buffer.allocUnsafe(13+o);q(c,c.length-4,0),c[4]=Zt.DATA,q(c,t,5),q(c,o,a),o&&(s?c.set(e,a+=4):i?c.utf8Write(e,a+=4,o):c.write(e,a+=4,o,r));let f=Xe(this,c);this._debug&&this._debug(`SFTP: Outbound: ${f?"Buffered":"Sending"} DATA`)}name(t,e){if(!this.server)throw new Error("Server-only method called in client mode");if(!Array.isArray(e)){if(typeof e!="object"||e===null)throw new Error("names is not an object or array");e=[e]}let r=e.length,s=0,i,o=[];for(let l=0;l<r;++l){let u=e[l],h=!u||!u.filename||typeof u.filename!="string"?"":u.filename;s+=4+Buffer.byteLength(h);let g=!u||!u.longname||typeof u.longname!="string"?"":u.longname;if(s+=4+Buffer.byteLength(g),typeof u.attrs=="object"&&u.attrs!==null){if(i=cr(u.attrs),s+=4+i.nb,i.nb){let y;i.nb===Re.length?y=new Uint8Array(Re):(y=new Uint8Array(i.nb),Vn(Re,y,0,i.nb,0)),i.bytes=y}o.push(i)}else s+=4,o.push(null)}let a=9,c=Buffer.allocUnsafe(13+s);q(c,c.length-4,0),c[4]=Zt.NAME,q(c,t,5),q(c,r,a),a+=4;for(let l=0;l<r;++l){let u=e[l];{let g=!u||!u.filename||typeof u.filename!="string"?"":u.filename,y=Buffer.byteLength(g);q(c,y,a),a+=4,y&&(c.utf8Write(g,a,y),a+=y)}{let g=!u||!u.longname||typeof u.longname!="string"?"":u.longname,y=Buffer.byteLength(g);q(c,y,a),a+=4,y&&(c.utf8Write(g,a,y),a+=y)}let h=o[l];h?(q(c,h.flags,a),a+=4,h.flags&&h.bytes&&(c.set(h.bytes,a),a+=h.nb)):(q(c,0,a),a+=4)}let f=Xe(this,c);this._debug&&this._debug(`SFTP: Outbound: ${f?"Buffered":"Sending"} NAME`)}attrs(t,e){if(!this.server)throw new Error("Server-only method called in client mode");if(typeof e!="object"||e===null)throw new Error("attrs is not an object");e=cr(e);let r=e.flags,s=e.nb,i=9,o=Buffer.allocUnsafe(13+s);q(o,o.length-4,0),o[4]=Zt.ATTRS,q(o,t,5),q(o,r,i),s&&(i+=4,s===Re.length?o.set(Re,i):Vn(Re,o,0,s,i),i+=s);let a=Xe(this,o);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} ATTRS`)}};function e0(n){try{return Buffer.allocUnsafe(n)}catch(t){return t}}function cl(n,t,e,r,s,i,o,a){let c=n._maxReadLen,f=Math.max(s-c,0);f&&(s=c);let l=t.length,u=9,h=i,g=Buffer.allocUnsafe(13+l+8+4);q(g,g.length-4,0),g[4]=ke.READ;let y=n._writeReqid=n._writeReqid+1&ft;q(g,y,5),q(g,l,u),g.set(t,u+=4),u+=l;for(let C=7;C>=0;--C)g[u+C]=h&255,h/=256;q(g,s,u+=8),typeof o!="function"&&(o=al);let _=a||{nb:0,position:i,off:r,origOff:r,len:void 0,overflow:void 0,cb:(C,L,F)=>{let k=_.len,K=_.overflow;if(C){if(o._wantEOFError||C.code!==et.EOF)return o(C)}else{if(F>k)return o(new Error("Received more data than requested"));if(F===k&&K){_.nb+=F,_.position+=F,_.off+=F,cl(n,t,e,_.off,K,_.position,o,_);return}}F=F||0,_.origOff===0&&e.length===_.nb?L=e:L=Or(e,_.origOff,_.origOff+_.nb+F),o(void 0,_.nb+F,L,_.position)},buffer:void 0};_.len=s,_.overflow=f,_.buffer=Or(e,r,r+s),n._requests[y]=_;let b=Xe(n,g);n._debug&&n._debug(`SFTP: Outbound: ${b?"Buffered":"Sending"} READ`)}function tl(n,t,e,r,s,i){let o=64,a=32768,c,f,l;typeof s=="function"?i=s:typeof s=="object"&&s!==null&&(typeof s.concurrency=="number"&&s.concurrency>0&&!isNaN(s.concurrency)&&(o=s.concurrency),typeof s.chunkSize=="number"&&s.chunkSize>0&&!isNaN(s.chunkSize)&&(a=s.chunkSize),typeof s.fileSize=="number"&&s.fileSize>0&&!isNaN(s.fileSize)&&(l=s.fileSize),typeof s.step=="function"&&(c=s.step),(typeof s.mode=="string"||typeof s.mode=="number")&&(f=Sa(s.mode)));let u,h=0,g=0,y=!1,_,b,C,L=a*o;function F(k){if(y)return;y=!0;let K=0,ee;_||b?(ee=()=>{--K===0&&i(k)},_&&(n===Gn||n.outgoing.state==="open")&&++K,b&&(t===Gn||t.outgoing.state==="open")&&++K,_&&(n===Gn||n.outgoing.state==="open")&&n.close(_,ee),b&&(t===Gn||t.outgoing.state==="open")&&t.close(b,ee)):i(k)}n.open(e,"r",(k,K)=>{if(k)return F(k);_=K,l===void 0?n.fstat(_,ee):ee(null,{size:l});function ee(O,x){if(O){if(n!==Gn){n.stat(e,(w,I)=>{if(w)return F(O);ee(null,I)});return}return F(O)}u=x.size,t.open(r,"w",(w,I)=>{if(w)return F(w);if(b=I,u<=0)return F();for(;L>u;){if(o===1){L=u;break}L-=a,--o}if(C=e0(L),C instanceof Error)return F(C);f!==void 0?t.fchmod(b,f,function Y(te){if(te){t.chmod(r,f,ce=>Y());return}G()}):G();function U(Y,te,ce,D,v,N){if(Y)return F(Y);v=v||0,t.write(b,C,v,te,D,H);function H(X){if(X)return F(X);if(g+=te,c&&c(g,te,u),te<N)return re(v,D+te,N-te);if(g===u){t.close(b,se=>{if(b=void 0,se)return F(se);n.close(_,ze=>{if(_=void 0,ze)return F(ze);i()})});return}if(h>=u)return;let fe=h+a>u?u-h:a;re(v,h,fe),h+=fe}}function R(Y,te,ce){return(D,v,N)=>{U(D,v,N,te,Y,ce)}}function re(Y,te,ce){n.read(_,C,Y,ce,te,R(Y,te,ce))}function G(){let Y=0,te=0;for(;h<u&&Y<o;){let ce=h+a>u?u-h:a;re(te,h,ce),te+=ce,h+=ce,++Y}}})}})}function Ea(n,t,e,r,s,i,o){let a=typeof o=="function"?o:void 0;n.write(t,e,r,s,i,(c,f)=>{if(c)return n.close(t,()=>{a&&a(c)});f===s?n.close(t,a):(r+=f,s-=f,i+=f,Ea(n,t,e,r,s,i,a))})}var Ss=class{constructor(t){this.mode=t&&t.mode,this.uid=t&&t.uid,this.gid=t&&t.gid,this.size=t&&t.size,this.atime=t&&t.atime,this.mtime=t&&t.mtime,this.extended=t&&t.extended}isDirectory(){return(this.mode&Jt.S_IFMT)===Jt.S_IFDIR}isFile(){return(this.mode&Jt.S_IFMT)===Jt.S_IFREG}isBlockDevice(){return(this.mode&Jt.S_IFMT)===Jt.S_IFBLK}isCharacterDevice(){return(this.mode&Jt.S_IFMT)===Jt.S_IFCHR}isSymbolicLink(){return(this.mode&Jt.S_IFMT)===Jt.S_IFLNK}isFIFO(){return(this.mode&Jt.S_IFMT)===Jt.S_IFIFO}isSocket(){return(this.mode&Jt.S_IFMT)===Jt.S_IFSOCK}};function cr(n){let t=0,e=0;if(typeof n=="object"&&n!==null){if(typeof n.size=="number"){t|=Un.SIZE;let r=n.size;Re[e++]=r/72057594037927940,Re[e++]=r/281474976710656,Re[e++]=r/1099511627776,Re[e++]=r/4294967296,Re[e++]=r/16777216,Re[e++]=r/65536,Re[e++]=r/256,Re[e++]=r}if(typeof n.uid=="number"&&typeof n.gid=="number"){t|=Un.UIDGID;let r=n.uid,s=n.gid;Re[e++]=r>>>24,Re[e++]=r>>>16,Re[e++]=r>>>8,Re[e++]=r,Re[e++]=s>>>24,Re[e++]=s>>>16,Re[e++]=s>>>8,Re[e++]=s}if(typeof n.mode=="number"||typeof n.mode=="string"){let r=Sa(n.mode);t|=Un.PERMISSIONS,Re[e++]=r>>>24,Re[e++]=r>>>16,Re[e++]=r>>>8,Re[e++]=r}if((typeof n.atime=="number"||ma(n.atime))&&(typeof n.mtime=="number"||ma(n.mtime))){let r=Ur(n.atime),s=Ur(n.mtime);t|=Un.ACMODTIME,Re[e++]=r>>>24,Re[e++]=r>>>16,Re[e++]=r>>>8,Re[e++]=r,Re[e++]=s>>>24,Re[e++]=s>>>16,Re[e++]=s>>>8,Re[e++]=s}}return{flags:t,nb:e}}function Ur(n){if(typeof n=="number"&&n===n)return n;if(ma(n))return parseInt(n.getTime()/1e3,10);throw new Error(`Cannot parse time: ${n}`)}function Sa(n){if(typeof n=="number"&&n===n)return n;if(typeof n=="string")return Sa(parseInt(n,8));throw new Error(`Cannot parse mode: ${n}`)}var _a={r:Ie.READ,"r+":Ie.READ|Ie.WRITE,w:Ie.TRUNC|Ie.CREAT|Ie.WRITE,wx:Ie.TRUNC|Ie.CREAT|Ie.WRITE|Ie.EXCL,xw:Ie.TRUNC|Ie.CREAT|Ie.WRITE|Ie.EXCL,"w+":Ie.TRUNC|Ie.CREAT|Ie.READ|Ie.WRITE,"wx+":Ie.TRUNC|Ie.CREAT|Ie.READ|Ie.WRITE|Ie.EXCL,"xw+":Ie.TRUNC|Ie.CREAT|Ie.READ|Ie.WRITE|Ie.EXCL,a:Ie.APPEND|Ie.CREAT|Ie.WRITE,ax:Ie.APPEND|Ie.CREAT|Ie.WRITE|Ie.EXCL,xa:Ie.APPEND|Ie.CREAT|Ie.WRITE|Ie.EXCL,"a+":Ie.APPEND|Ie.CREAT|Ie.READ|Ie.WRITE,"ax+":Ie.APPEND|Ie.CREAT|Ie.READ|Ie.WRITE|Ie.EXCL,"xa+":Ie.APPEND|Ie.CREAT|Ie.READ|Ie.WRITE|Ie.EXCL};function fl(n){let t=_a[n];return t!==void 0?t:null}var t0=(()=>{let n=Object.keys(_a);return t=>{for(let e=0;e<n.length;++e){let r=n[e];if(_a[r]===t)return r}return null}})();function Dr(n){let t=M.readUInt32BE();if(t===void 0)return;let e=new Ss;if(t&Un.SIZE){let r=M.readUInt64BE(n);if(r===void 0)return;e.size=r}if(t&Un.UIDGID){let r=M.readUInt32BE(),s=M.readUInt32BE();if(s===void 0)return;e.uid=r,e.gid=s}if(t&Un.PERMISSIONS){let r=M.readUInt32BE();if(r===void 0)return;e.mode=r}if(t&Un.ACMODTIME){let r=M.readUInt32BE(),s=M.readUInt32BE();if(s===void 0)return;e.atime=r,e.mtime=s}if(t&Un.EXTENDED){let r=M.readUInt32BE();if(r===void 0)return;let s={};for(let i=0;i<r;++i){let o=M.readString(!0),a=M.readString();if(a===void 0)return;s[o]=a}e.extended=s}return e}function Xe(n,t){let e=ll(n,t);return e!==void 0?(n._buffer.push(e),!1):!0}function ll(n,t){let e=n.outgoing;if(e.state!=="open")return;if(e.window===0)return n._waitWindow=!0,n._chunkcb=nl,t;let r,s=t.length,i=0;for(;s-i>0&&e.window>0;){let o=Math.min(s-i,e.window,e.packetSize);e.window-=o,e.window===0&&(n._waitWindow=!0,n._chunkcb=nl),i===0&&o===s?n._protocol.channelData(n.outgoing.id,t):n._protocol.channelData(n.outgoing.id,Or(t,i,i+o)),i+=o}return s-i>0&&(i>0?r=Or(t,i,s):r=t),r}function nl(){this._chunkcb=void 0;let n=this._buffer,t=0;for(;t<n.length;){let e=n[t],r=ll(this,e);if(r!==void 0){r!==e&&(n[t]=r),t>0&&(this._buffer=n.slice(t));return}++t}t>0&&(this._buffer=[])}function it(n,t,e){let r=new Error(t);return r.level="sftp-protocol",!e&&n._debug&&n._debug(`SFTP: Inbound: ${t}`),n.emit("error",r),n.destroy(),ul(n),!1}function ul(n){let t=Object.keys(n._requests);if(t.length===0)return;let e=n._requests;n._requests={};let r=new Error("No response from server");for(let s=0;s<t.length;++s){let i=e[t[s]];typeof i.cb=="function"&&i.cb(r)}}function n0(n,t){let e=9,r=Buffer.allocUnsafe(31);q(r,r.length-4,0),r[4]=ke.EXTENDED;let s=n._writeReqid=n._writeReqid+1&ft;q(r,s,5),q(r,18,e),r.utf8Write("limits@openssh.com",e+=4,18),n._requests[s]={extended:"limits@openssh.com",cb:t};let i=Xe(n,r);if(n._debug){let o=i?"Buffered":"Sending";n._debug(`SFTP: Outbound: ${o} limits@openssh.com`)}}var r0={[Zt.VERSION]:(n,t)=>{if(n._version!==-1)return it(n,"Duplicate VERSION packet");let e={};M.init(t,1);let r=M.readUInt32BE();for(;M.avail();){let s=M.readString(!0),i=M.readString(!0);if(i===void 0){r=void 0;break}e[s]=i}if(M.clear(),r===void 0)return it(n,"Malformed VERSION packet");if(n._debug){let s=Object.keys(e);s.length?n._debug(`SFTP: Inbound: Received VERSION (v${r}, exts:${s})`):n._debug(`SFTP: Inbound: Received VERSION (v${r})`)}if(n._version=r,n._extensions=e,e["limits@openssh.com"]==="1")return n0(n,(s,i)=>{s||(i.maxPktLen>0&&(n._maxOutPktLen=i.maxPktLen),i.maxReadLen>0&&(n._maxReadLen=i.maxReadLen),i.maxWriteLen>0&&(n._maxWriteLen=i.maxWriteLen),n.maxOpenHandles=i.maxOpenHandles>0?i.maxOpenHandles:1/0),n.emit("ready")});n.emit("ready")},[Zt.STATUS]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readUInt32BE(),s=M.readString(!0);if(M.clear(),n._debug){let o=JSON.stringify(s);n._debug(`SFTP: Inbound: Received STATUS (id:${e}, ${r}, ${o})`)}let i=n._requests[e];if(delete n._requests[e],i&&typeof i.cb=="function"){if(r===et.OK){i.cb();return}let o=new Error(s||zg[r]||"Unknown status");o.code=r,i.cb(o)}},[Zt.HANDLE]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString();if(M.clear(),r===void 0)return e!==void 0&&delete n._requests[e],it(n,"Malformed HANDLE packet");n._debug&&n._debug(`SFTP: Inbound: Received HANDLE (id:${e})`);let s=n._requests[e];delete n._requests[e],s&&typeof s.cb=="function"&&s.cb(void 0,r)},[Zt.DATA]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r;if(e!==void 0&&(r=n._requests[e],delete n._requests[e]),r&&typeof r.cb=="function")if(r.buffer){let s=M.readString(r.buffer);if(M.clear(),s!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received DATA (id:${e}, ${s})`),r.cb(void 0,r.buffer,s);return}}else{let s=M.readString();if(M.clear(),s!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received DATA (id:${e}, ${s.length})`),r.cb(void 0,s);return}}else{let s=M.skipString();if(M.clear(),s!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received DATA (id:${e}, ${s})`);return}}return it(n,"Malformed DATA packet")},[Zt.NAME]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r;e!==void 0&&(r=n._requests[e],delete n._requests[e]);let s=M.readUInt32BE();if(s!==void 0){let i=[];for(let o=0;o<s;++o){let a=M.readString(!0),c=M.readString(!0),f=Dr(n._biOpt);if(f===void 0){i=void 0;break}i.push({filename:a,longname:c,attrs:f})}if(i!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received NAME (id:${e}, ${i.length})`),M.clear(),r&&typeof r.cb=="function"&&r.cb(void 0,i);return}}return M.clear(),it(n,"Malformed NAME packet")},[Zt.ATTRS]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r;e!==void 0&&(r=n._requests[e],delete n._requests[e]);let s=Dr(n._biOpt);if(M.clear(),s!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received ATTRS (id:${e})`),r&&typeof r.cb=="function"&&r.cb(void 0,s);return}return it(n,"Malformed ATTRS packet")},[Zt.EXTENDED]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE();if(e!==void 0){let r=n._requests[e];if(r)switch(delete n._requests[e],r.extended){case"statvfs@openssh.com":case"fstatvfs@openssh.com":{let s=n._biOpt,i={f_bsize:M.readUInt64BE(s),f_frsize:M.readUInt64BE(s),f_blocks:M.readUInt64BE(s),f_bfree:M.readUInt64BE(s),f_bavail:M.readUInt64BE(s),f_files:M.readUInt64BE(s),f_ffree:M.readUInt64BE(s),f_favail:M.readUInt64BE(s),f_sid:M.readUInt64BE(s),f_flag:M.readUInt64BE(s),f_namemax:M.readUInt64BE(s)};if(i.f_namemax===void 0)break;n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ${r.extended})`),M.clear(),typeof r.cb=="function"&&r.cb(void 0,i);return}case"limits@openssh.com":{let s={maxPktLen:M.readUInt64BE(),maxReadLen:M.readUInt64BE(),maxWriteLen:M.readUInt64BE(),maxOpenHandles:M.readUInt64BE()};if(s.maxOpenHandles===void 0)break;n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ${r.extended})`),M.clear(),typeof r.cb=="function"&&r.cb(void 0,s);return}case"users-groups-by-id@openssh.com":{let s=M.readUInt32BE();if(s===void 0)break;let i=new Array(s);for(let c=0;c<i.length;++c)i[c]=M.readString(!0);let o=M.readUInt32BE();if(o===void 0)break;let a=new Array(o);for(let c=0;c<a.length;++c)a[c]=M.readString(!0);if(a.length>0&&a[a.length-1]===void 0)break;n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ${r.extended})`),M.clear(),typeof r.cb=="function"&&r.cb(void 0,i,a);return}default:n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ???)`),M.clear(),typeof r.cb=="function"&&r.cb();return}else{n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ???)`),M.clear();return}}return M.clear(),it(n,"Malformed EXTENDED_REPLY packet")}},i0={[ke.INIT]:(n,t)=>{if(n._version!==-1)return it(n,"Duplicate INIT packet");let e={};M.init(t,1);let r=M.readUInt32BE();for(;M.avail();){let s=M.readString(!0),i=M.readString(!0);if(i===void 0){r=void 0;break}e[s]=i}if(M.clear(),r===void 0)return it(n,"Malformed INIT packet");if(n._debug){let s=Object.keys(e);s.length?n._debug(`SFTP: Inbound: Received INIT (v${r}, exts:${s})`):n._debug(`SFTP: Inbound: Received INIT (v${r})`)}Xe(n,Xg),n._version=r,n._extensions=e,n.emit("ready")},[ke.OPEN]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0),s=M.readUInt32BE(),i=Dr(n._biOpt);if(M.clear(),i===void 0)return it(n,"Malformed OPEN packet");n._debug&&n._debug(`SFTP: Inbound: Received OPEN (id:${e})`),n.emit("OPEN",e,r,s,i)||n.status(e,et.OP_UNSUPPORTED)},[ke.CLOSE]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString();if(M.clear(),r===void 0||r.length>256)return it(n,"Malformed CLOSE packet");n._debug&&n._debug(`SFTP: Inbound: Received CLOSE (id:${e})`),n.emit("CLOSE",e,r)||n.status(e,et.OP_UNSUPPORTED)},[ke.READ]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(),s=M.readUInt64BE(n._biOpt),i=M.readUInt32BE();if(M.clear(),i===void 0||r.length>256)return it(n,"Malformed READ packet");n._debug&&n._debug(`SFTP: Inbound: Received READ (id:${e})`),n.emit("READ",e,r,s,i)||n.status(e,et.OP_UNSUPPORTED)},[ke.WRITE]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(),s=M.readUInt64BE(n._biOpt),i=M.readString();if(M.clear(),i===void 0||r.length>256)return it(n,"Malformed WRITE packet");n._debug&&n._debug(`SFTP: Inbound: Received WRITE (id:${e})`),n.emit("WRITE",e,r,s,i)||n.status(e,et.OP_UNSUPPORTED)},[ke.LSTAT]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0);if(M.clear(),r===void 0)return it(n,"Malformed LSTAT packet");n._debug&&n._debug(`SFTP: Inbound: Received LSTAT (id:${e})`),n.emit("LSTAT",e,r)||n.status(e,et.OP_UNSUPPORTED)},[ke.FSTAT]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString();if(M.clear(),r===void 0||r.length>256)return it(n,"Malformed FSTAT packet");n._debug&&n._debug(`SFTP: Inbound: Received FSTAT (id:${e})`),n.emit("FSTAT",e,r)||n.status(e,et.OP_UNSUPPORTED)},[ke.SETSTAT]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0),s=Dr(n._biOpt);if(M.clear(),s===void 0)return it(n,"Malformed SETSTAT packet");n._debug&&n._debug(`SFTP: Inbound: Received SETSTAT (id:${e})`),n.emit("SETSTAT",e,r,s)||n.status(e,et.OP_UNSUPPORTED)},[ke.FSETSTAT]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(),s=Dr(n._biOpt);if(M.clear(),s===void 0||r.length>256)return it(n,"Malformed FSETSTAT packet");n._debug&&n._debug(`SFTP: Inbound: Received FSETSTAT (id:${e})`),n.emit("FSETSTAT",e,r,s)||n.status(e,et.OP_UNSUPPORTED)},[ke.OPENDIR]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0);if(M.clear(),r===void 0)return it(n,"Malformed OPENDIR packet");n._debug&&n._debug(`SFTP: Inbound: Received OPENDIR (id:${e})`),n.emit("OPENDIR",e,r)||n.status(e,et.OP_UNSUPPORTED)},[ke.READDIR]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString();if(M.clear(),r===void 0||r.length>256)return it(n,"Malformed READDIR packet");n._debug&&n._debug(`SFTP: Inbound: Received READDIR (id:${e})`),n.emit("READDIR",e,r)||n.status(e,et.OP_UNSUPPORTED)},[ke.REMOVE]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0);if(M.clear(),r===void 0)return it(n,"Malformed REMOVE packet");n._debug&&n._debug(`SFTP: Inbound: Received REMOVE (id:${e})`),n.emit("REMOVE",e,r)||n.status(e,et.OP_UNSUPPORTED)},[ke.MKDIR]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0),s=Dr(n._biOpt);if(M.clear(),s===void 0)return it(n,"Malformed MKDIR packet");n._debug&&n._debug(`SFTP: Inbound: Received MKDIR (id:${e})`),n.emit("MKDIR",e,r,s)||n.status(e,et.OP_UNSUPPORTED)},[ke.RMDIR]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0);if(M.clear(),r===void 0)return it(n,"Malformed RMDIR packet");n._debug&&n._debug(`SFTP: Inbound: Received RMDIR (id:${e})`),n.emit("RMDIR",e,r)||n.status(e,et.OP_UNSUPPORTED)},[ke.REALPATH]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0);if(M.clear(),r===void 0)return it(n,"Malformed REALPATH packet");n._debug&&n._debug(`SFTP: Inbound: Received REALPATH (id:${e})`),n.emit("REALPATH",e,r)||n.status(e,et.OP_UNSUPPORTED)},[ke.STAT]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0);if(M.clear(),r===void 0)return it(n,"Malformed STAT packet");n._debug&&n._debug(`SFTP: Inbound: Received STAT (id:${e})`),n.emit("STAT",e,r)||n.status(e,et.OP_UNSUPPORTED)},[ke.RENAME]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0),s=M.readString(!0);if(M.clear(),s===void 0)return it(n,"Malformed RENAME packet");n._debug&&n._debug(`SFTP: Inbound: Received RENAME (id:${e})`),n.emit("RENAME",e,r,s)||n.status(e,et.OP_UNSUPPORTED)},[ke.READLINK]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0);if(M.clear(),r===void 0)return it(n,"Malformed READLINK packet");n._debug&&n._debug(`SFTP: Inbound: Received READLINK (id:${e})`),n.emit("READLINK",e,r)||n.status(e,et.OP_UNSUPPORTED)},[ke.SYMLINK]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0),s=M.readString(!0);if(M.clear(),s===void 0)return it(n,"Malformed SYMLINK packet");n._debug&&n._debug(`SFTP: Inbound: Received SYMLINK (id:${e})`);let i;n._isOpenSSH?i=n.emit("SYMLINK",e,s,r):i=n.emit("SYMLINK",e,r,s),i||n.status(e,et.OP_UNSUPPORTED)},[ke.EXTENDED]:(n,t)=>{M.init(t,1);let e=M.readUInt32BE(),r=M.readString(!0);if(r===void 0)return M.clear(),it(n,"Malformed EXTENDED packet");let s;M.avail()&&(s=M.readRaw()),M.clear(),n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED (id:${e})`),n.emit("EXTENDED",e,r,s)||n.status(e,et.OP_UNSUPPORTED)}},{ERR_INVALID_ARG_TYPE:s0,ERR_OUT_OF_RANGE:xs,validateNumber:o0}=Zf(),rl=128,Yt,ya=[];function a0(n){ya.length>0?Yt=ya.pop():Yt=Buffer.allocUnsafe(n),Yt.used=0}function ba(n,t){if(!Number.isSafeInteger(n))throw o0(n,t),Number.isInteger(n)?new xs(t,">= 0 and <= 2 ** 53 - 1",n):new xs(t,"an integer",n);if(n<0)throw new xs(t,">= 0 and <= 2 ** 53 - 1",n)}function ga(n){return n+7&-8}function Dn(n,t,e){if(e===void 0)e={};else if(typeof e=="string")e={encoding:e};else{if(e===null||typeof e!="object")throw new TypeError('"options" argument must be a string or an object');e=Object.create(e)}if(e.highWaterMark===void 0&&(e.highWaterMark=64*1024),e.emitClose=!1,e.autoDestroy=!1,sl.call(this,e),this.path=t,this.flags=e.flags===void 0?"r":e.flags,this.mode=e.mode===void 0?438:e.mode,this.start=e.start,this.end=e.end,this.autoClose=e.autoClose===void 0?!0:e.autoClose,this.pos=0,this.bytesRead=0,this.isClosed=!1,this.handle=e.handle===void 0?null:e.handle,this.sftp=n,this._opening=!1,this.start!==void 0&&(ba(this.start,"start"),this.pos=this.start),this.end===void 0)this.end=1/0;else if(this.end!==1/0&&(ba(this.end,"end"),this.start!==void 0&&this.start>this.end))throw new xs("start",`<= "end" (here: ${this.end})`,this.start);this.on("end",function(){this.autoClose&&this.destroy()}),Buffer.isBuffer(this.handle)||this.open()}ol(Dn,sl);Dn.prototype.open=function(){this._opening||(this._opening=!0,this.sftp.open(this.path,this.flags,this.mode,(n,t)=>{if(this._opening=!1,n){this.emit("error",n),this.autoClose&&this.destroy();return}this.handle=t,this.emit("open",t),this.emit("ready"),this.read()}))};Dn.prototype._read=function(n){if(!Buffer.isBuffer(this.handle))return this.once("open",()=>this._read(n));if(this.destroyed)return;(!Yt||Yt.length-Yt.used<rl)&&a0(this.readableHighWaterMark||this._readableState.highWaterMark);let t=Yt,e=Math.min(Yt.length-Yt.used,n),r=Yt.used;if(this.end!==void 0&&(e=Math.min(this.end-this.pos+1,e)),e<=0)return this.push(null);this.sftp.read(this.handle,Yt,Yt.used,e,this.pos,(s,i)=>{if(s){this.emit("error",s),this.autoClose&&this.destroy();return}let o=null;if(r+e===t.used&&t===Yt)t.used=ga(t.used+i-e);else{let a=r+e&-8,c=ga(r+i);a-c>=rl&&ya.push(t.slice(c,a))}i>0&&(this.bytesRead+=i,o=t.slice(r,r+i)),this.pos+=i,this.push(o)}),Yt.used=ga(Yt.used+e)};Dn.prototype._destroy=function(n,t){if(this._opening&&!Buffer.isBuffer(this.handle)){this.once("open",il.bind(null,this,t,n));return}il(this,t,n),this.handle=null,this._opening=!1};function il(n,t,e){if(!n.handle)return r();n.sftp.close(n.handle,r);function r(s){s=s||e,t(s),n.isClosed=!0,s||n.emit("close")}}Dn.prototype.close=function(n){this.destroy(null,n)};Object.defineProperty(Dn.prototype,"pending",{get(){return this.handle===null},configurable:!0});function un(n,t,e){if(e===void 0)e={};else if(typeof e=="string")e={encoding:e};else{if(e===null||typeof e!="object")throw new TypeError('"options" argument must be a string or an object');e=Object.create(e)}e.emitClose=!1,e.autoDestroy=!1,xa.call(this,e),this.path=t,this.flags=e.flags===void 0?"w":e.flags,this.mode=e.mode===void 0?438:e.mode,this.start=e.start,this.autoClose=e.autoClose===void 0?!0:e.autoClose,this.pos=0,this.bytesWritten=0,this.isClosed=!1,this.handle=e.handle===void 0?null:e.handle,this.sftp=n,this._opening=!1,this.start!==void 0&&(ba(this.start,"start"),this.pos=this.start),e.encoding&&this.setDefaultEncoding(e.encoding),this.on("finish",function(){this._writableState.finalCalled||this.autoClose&&this.destroy()}),Buffer.isBuffer(this.handle)||this.open()}ol(un,xa);un.prototype._final=function(n){this.autoClose&&this.destroy(),n()};un.prototype.open=function(){this._opening||(this._opening=!0,this.sftp.open(this.path,this.flags,this.mode,(n,t)=>{if(this._opening=!1,n){this.emit("error",n),this.autoClose&&this.destroy();return}this.handle=t;let e=r=>{if(r){this.sftp.chmod(this.path,this.mode,s=>e());return}if(this.flags[0]==="a"){let s=(i,o)=>{if(i){this.sftp.stat(this.path,(a,c)=>{if(a){this.destroy(),this.emit("error",i);return}s(null,c)});return}this.pos=o.size,this.emit("open",t),this.emit("ready")};this.sftp.fstat(t,s);return}this.emit("open",t),this.emit("ready")};this.sftp.fchmod(t,this.mode,e)}))};un.prototype._write=function(n,t,e){if(!Buffer.isBuffer(n)){let r=new s0("data","Buffer",n);return this.emit("error",r)}if(!Buffer.isBuffer(this.handle))return this.once("open",function(){this._write(n,t,e)});this.sftp.write(this.handle,n,0,n.length,this.pos,(r,s)=>{if(r)return this.autoClose&&this.destroy(),e(r);this.bytesWritten+=s,e()}),this.pos+=n.length};un.prototype._writev=function(n,t){if(!Buffer.isBuffer(this.handle))return this.once("open",function(){this._writev(n,t)});let e=this.sftp,r=this.handle,s=n.length,i=(o,a)=>{if(o)return this.destroy(),t(o);this.bytesWritten+=a,--s===0&&t()};for(let o=0;o<n.length;++o){let a=n[o].chunk;e.write(r,a,0,a.length,this.pos,i),this.pos+=a.length}};typeof xa.prototype.destroy!="function"&&(un.prototype.destroy=Dn.prototype.destroy);un.prototype._destroy=Dn.prototype._destroy;un.prototype.close=function(n){if(n){if(this.isClosed){process.nextTick(n);return}this.on("close",n)}this.autoClose||this.on("finish",this.destroy.bind(this)),this.end()};un.prototype.destroySoon=un.prototype.end;Object.defineProperty(un.prototype,"pending",{get(){return this.handle===null},configurable:!0});dl.exports={flagsToString:t0,OPEN_MODE:Ie,SFTP:Aa,Stats:Ss,STATUS_CODE:et,stringToFlags:fl}});var Ba=at((vE,ml)=>{"use strict";var{Duplex:c0,Readable:f0,Writable:l0}=require("stream"),{CHANNEL_EXTENDED_DATATYPE:{STDERR:hl}}=Pn(),{bufferSlice:ws}=dn(),u0=32*1024,xi=2*1024*1024,va=xi/2,wa=class extends f0{constructor(t,e){super(e),this._channel=t}_read(t){this._channel._waitChanDrain&&(this._channel._waitChanDrain=!1,this._channel.incoming.window<=va&&ka(this._channel))}},Ia=class extends l0{constructor(t){super({highWaterMark:xi}),this._channel=t}_write(t,e,r){let s=this._channel,i=s._client._protocol,o=s.outgoing,a=o.packetSize,c=o.id,f=o.window,l=t.length,u=0;if(o.state==="open"){for(;l-u>0&&f>0;){let h=l-u;h>f&&(h=f),h>a&&(h=a),u===0&&h===l?i.channelExtData(c,t,hl):i.channelExtData(c,ws(t,u,u+h),hl),u+=h,f-=h}if(o.window=f,l-u>0){f===0&&(s._waitWindow=!0),u>0?s._chunkErr=ws(t,u,l):s._chunkErr=t,s._chunkcbErr=r;return}r()}}},Ca=class extends c0{constructor(t,e,r){let s={highWaterMark:xi,allowHalfOpen:!r||r&&r.allowHalfOpen!==!1,emitClose:!1};super(s),this.allowHalfOpen=s.allowHalfOpen;let i=!!(r&&r.server);this.server=i,this.type=e.type,this.subtype=void 0,this.incoming=e.incoming,this.outgoing=e.outgoing,this._callbacks=[],this._client=t,this._hasX11=!1,this._exit={code:void 0,signal:void 0,dump:void 0,desc:void 0},this.stdin=this.stdout=this,i?this.stderr=new Ia(this):this.stderr=new wa(this,s),this._waitWindow=!1,this._waitChanDrain=!1,this._chunk=void 0,this._chunkcb=void 0,this._chunkErr=void 0,this._chunkcbErr=void 0,this.on("finish",pl).on("prefinish",pl),this.on("end",gl).on("close",gl)}_read(t){this._waitChanDrain&&(this._waitChanDrain=!1,this.incoming.window<=va&&ka(this))}_write(t,e,r){let s=this._client._protocol,i=this.outgoing,o=i.packetSize,a=i.id,c=i.window,f=t.length,l=0;if(i.state==="open"){for(;f-l>0&&c>0;){let u=f-l;u>c&&(u=c),u>o&&(u=o),l===0&&u===f?s.channelData(a,t):s.channelData(a,ws(t,l,l+u)),l+=u,c-=u}if(i.window=c,f-l>0){c===0&&(this._waitWindow=!0),l>0?this._chunk=ws(t,l,f):this._chunk=t,this._chunkcb=r;return}r()}}eof(){this.outgoing.state==="open"&&(this.outgoing.state="eof",this._client._protocol.channelEOF(this.outgoing.id))}close(){(this.outgoing.state==="open"||this.outgoing.state==="eof")&&(this.outgoing.state="closing",this._client._protocol.channelClose(this.outgoing.id))}destroy(){return this.end(),this.close(),this}setWindow(t,e,r,s){if(this.server)throw new Error("Client-only method called in server mode");this.type==="session"&&(this.subtype==="shell"||this.subtype==="exec")&&this.writable&&this.outgoing.state==="open"&&this._client._protocol.windowChange(this.outgoing.id,t,e,r,s)}signal(t){if(this.server)throw new Error("Client-only method called in server mode");this.type==="session"&&this.writable&&this.outgoing.state==="open"&&this._client._protocol.signal(this.outgoing.id,t)}exit(t,e,r){if(!this.server)throw new Error("Server-only method called in client mode");this.type==="session"&&this.writable&&this.outgoing.state==="open"&&(typeof t=="number"?this._client._protocol.exitStatus(this.outgoing.id,t):this._client._protocol.exitSignal(this.outgoing.id,t,e,r))}};function pl(){this.eof(),(this.server||!this.allowHalfOpen)&&this.close(),this.writable=!1}function gl(){this.readable=!1}function ka(n){if(n.outgoing.state==="closed")return;let t=xi-n.incoming.window;t<=0||(n.incoming.window+=t,n._client._protocol.channelWindowAdjust(n.outgoing.id,t))}ml.exports={Channel:Ca,MAX_WINDOW:xi,PACKET_SIZE:u0,windowAdjust:ka,WINDOW_THRESHOLD:va}});var Pa=at((kE,_l)=>{"use strict";var{SFTP:d0}=bi(),Si=2**32-1;function Al(n,t,e,r){if(n._chanMgr.remove(t),typeof r!="function")return;let s;e instanceof Error?s=e:typeof e=="object"&&e!==null?(s=new Error(`(SSH) Channel open failure: ${e.description}`),s.reason=e.reason):(s=new Error("(SSH) Channel open failure: server closed channel unexpectedly"),s.reason=""),r(s)}function El(n,t,e,r,s){if(typeof e=="function"){Al(n,t,r,e);return}if(typeof e!="object"||e===null||e.incoming&&e.incoming.state==="closed"||(n._chanMgr.remove(t),e.server&&e.constructor.name==="Session"))return;e.incoming.state="closed",e.readable&&e.push(null),e.server?e.stderr.writable&&e.stderr.end():e.stderr.readable&&e.stderr.push(null),e.constructor!==d0&&(e.outgoing.state==="open"||e.outgoing.state==="eof")&&!s&&e.close(),e.outgoing.state==="closing"&&(e.outgoing.state="closed");let i=e._readableState,o=e._writableState;o&&!o.ending&&!o.finished&&!s&&e.end();let a=e._callbacks;e._callbacks=[];for(let c=0;c<a.length;++c)a[c](!0);if(e.server)!e.readable||e.destroyed||i&&i.endEmitted?e.emit("close"):e.once("end",()=>e.emit("close"));else{let c;switch(e.type){case"direct-streamlocal@openssh.com":case"direct-tcpip":c=()=>e.emit("close");break;default:{let l=e._exit;c=()=>{l.code===null?e.emit("close",l.code,l.signal,l.dump,l.desc):e.emit("close",l.code)}}}!e.readable||e.destroyed||i&&i.endEmitted?c():e.once("end",c);let f=e.stderr._readableState;!e.stderr.readable||e.stderr.destroyed||f&&f.endEmitted?e.stderr.emit("close"):e.stderr.once("end",()=>e.stderr.emit("close"))}}var Na=class{constructor(t){this._client=t,this._channels={},this._cur=-1,this._count=0}add(t){let e;if(this._cur<Si)e=++this._cur;else if(this._count===0)this._cur=0,e=0;else{let r=this._channels;for(let s=0;s<Si;++s)if(r[s]===void 0){e=s;break}}return e===void 0?-1:(this._channels[e]=t||!0,++this._count,e)}update(t,e){if(typeof t!="number"||t<0||t>=Si||!isFinite(t))throw new Error(`Invalid channel id: ${t}`);e&&this._channels[t]&&(this._channels[t]=e)}get(t){if(typeof t!="number"||t<0||t>=Si||!isFinite(t))throw new Error(`Invalid channel id: ${t}`);return this._channels[t]}remove(t){if(typeof t!="number"||t<0||t>=Si||!isFinite(t))throw new Error(`Invalid channel id: ${t}`);this._channels[t]&&(delete this._channels[t],this._count&&--this._count)}cleanup(t){let e=this._channels;this._channels={},this._cur=-1,this._count=0;let r=Object.keys(e),s=this._client;for(let i=0;i<r.length;++i){let o=+r[i],a=e[o];El(s,o,a._channel||a,t,!0)}}},Ra=(()=>{let n=Object.prototype.toString;return t=>n.call(t)==="[object RegExp]"})();function h0(n,t,e){if(Array.isArray(n)&&n.length>0){for(let r=0;r<n.length;++r)if(e.indexOf(n[r])===-1)throw new Error(`Unsupported algorithm: ${n[r]}`);return n}if(typeof n=="object"&&n!==null){let r=Object.keys(n),s=t;for(let i=0;i<r.length;++i){let o=r[i],a=n[o];switch(o){case"append":if(Array.isArray(a)||(a=[a]),Array.isArray(a))for(let c=0;c<a.length;++c){let f=a[c];if(typeof f=="string"){if(!f||s.indexOf(f)!==-1)continue;if(e.indexOf(f)===-1)throw new Error(`Unsupported algorithm: ${f}`);s===t&&(s=s.slice()),s.push(f)}else if(Ra(f))for(let l=0;l<e.length;++l){let u=e[l];if(f.test(u)){if(s.indexOf(u)!==-1)continue;s===t&&(s=s.slice()),s.push(u)}}}break;case"prepend":if(Array.isArray(a)||(a=[a]),Array.isArray(a))for(let c=a.length;c>=0;--c){let f=a[c];if(typeof f=="string"){if(!f||s.indexOf(f)!==-1)continue;if(e.indexOf(f)===-1)throw new Error(`Unsupported algorithm: ${f}`);s===t&&(s=s.slice()),s.unshift(f)}else if(Ra(f))for(let l=e.length;l>=0;--l){let u=e[l];if(f.test(u)){if(s.indexOf(u)!==-1)continue;s===t&&(s=s.slice()),s.unshift(u)}}}break;case"remove":if(Array.isArray(a)||(a=[a]),Array.isArray(a))for(let c=0;c<a.length;++c){let f=a[c];if(typeof f=="string"){if(!f)continue;let l=s.indexOf(f);if(l===-1)continue;s===t&&(s=s.slice()),s.splice(l,1)}else if(Ra(f))for(let l=0;l<s.length;++l)f.test(s[l])&&(s===t&&(s=s.slice()),s.splice(l,1),--l)}break}}return s}return t}_l.exports={ChannelManager:Na,generateAlgorithmList:h0,onChannelOpenFailure:Al,onCHANNEL_CLOSE:El,isWritable:n=>n&&n.writable&&n._readableState&&n._readableState.ended===!1}});var $a=at((BE,$l)=>{"use strict";var{createHash:p0,getHashes:g0,randomFillSync:m0}=require("crypto"),{Socket:A0}=require("net"),{lookup:E0}=require("dns"),_0=require("events"),y0=g0(),{COMPAT:Dl,CHANNEL_EXTENDED_DATATYPE:{STDERR:b0},CHANNEL_OPEN_FAILURE:wi,DEFAULT_CIPHER:yl,DEFAULT_COMPRESSION:bl,DEFAULT_KEX:xl,DEFAULT_MAC:Sl,DEFAULT_SERVER_HOST_KEY:wl,DISCONNECT_REASON:Il,DISCONNECT_REASON_BY_VALUE:x0,SUPPORTED_CIPHER:S0,SUPPORTED_COMPRESSION:w0,SUPPORTED_KEX:I0,SUPPORTED_MAC:C0,SUPPORTED_SERVER_HOST_KEY:v0}=Pn(),{init:k0}=Qn(),B0=ha(),{parseKey:vs}=Kn(),{SFTP:R0}=bi(),{bufferCopy:Cl,makeBufferParser:Ol,makeError:N0,readUInt32BE:P0,sigSSHToASN1:T0,writeUInt32BE:Ta}=dn(),{AgentContext:vl,createAgent:kl,isAgent:Bl}=Jo(),{Channel:Ml,MAX_WINDOW:ks,PACKET_SIZE:Bs,windowAdjust:Rl,WINDOW_THRESHOLD:Nl}=Ba(),{ChannelManager:L0,generateAlgorithmList:Ii,isWritable:Pt,onChannelOpenFailure:U0,onCHANNEL_CLOSE:D0}=Pa(),Is=Ol(),Cs=Ol(),Ci=/^OpenSSH_(?:(?![0-4])\d)|(?:\d{2,})/,Oa=n=>{},Ma=class extends _0{constructor(){super(),this.config={host:void 0,port:void 0,localAddress:void 0,localPort:void 0,forceIPv4:void 0,forceIPv6:void 0,keepaliveCountMax:void 0,keepaliveInterval:void 0,readyTimeout:void 0,ident:void 0,username:void 0,password:void 0,privateKey:void 0,tryKeyboard:void 0,agent:void 0,allowAgentFwd:void 0,authHandler:void 0,hostHashAlgo:void 0,hostHashCb:void 0,strictVendor:void 0,debug:void 0},this._agent=void 0,this._readyTimeout=void 0,this._chanMgr=void 0,this._callbacks=void 0,this._forwarding=void 0,this._forwardingUnix=void 0,this._acceptX11=void 0,this._agentFwdEnabled=void 0,this._remoteVer=void 0,this._protocol=void 0,this._sock=void 0,this._resetKA=void 0}connect(t){if(this._sock&&Pt(this._sock))return this.once("close",()=>{this.connect(t)}),this.end(),this;this.config.host=t.hostname||t.host||"localhost",this.config.port=t.port||22,this.config.localAddress=typeof t.localAddress=="string"?t.localAddress:void 0,this.config.localPort=typeof t.localPort=="string"||typeof t.localPort=="number"?t.localPort:void 0,this.config.forceIPv4=t.forceIPv4||!1,this.config.forceIPv6=t.forceIPv6||!1,this.config.keepaliveCountMax=typeof t.keepaliveCountMax=="number"&&t.keepaliveCountMax>=0?t.keepaliveCountMax:3,this.config.keepaliveInterval=typeof t.keepaliveInterval=="number"&&t.keepaliveInterval>0?t.keepaliveInterval:0,this.config.readyTimeout=typeof t.readyTimeout=="number"&&t.readyTimeout>=0?t.readyTimeout:2e4,this.config.ident=typeof t.ident=="string"||Buffer.isBuffer(t.ident)?t.ident:void 0;let e={kex:void 0,serverHostKey:void 0,cs:{cipher:void 0,mac:void 0,compress:void 0,lang:[]},sc:void 0},r=!0;if(typeof t.algorithms=="object"&&t.algorithms!==null&&(e.kex=Ii(t.algorithms.kex,xl,I0),e.kex!==xl&&(r=!1),e.serverHostKey=Ii(t.algorithms.serverHostKey,wl,v0),e.serverHostKey!==wl&&(r=!1),e.cs.cipher=Ii(t.algorithms.cipher,yl,S0),e.cs.cipher!==yl&&(r=!1),e.cs.mac=Ii(t.algorithms.hmac,Sl,C0),e.cs.mac!==Sl&&(r=!1),e.cs.compress=Ii(t.algorithms.compress,bl,w0),e.cs.compress!==bl&&(r=!1),r||(e.sc=e.cs)),typeof t.username=="string")this.config.username=t.username;else if(typeof t.user=="string")this.config.username=t.user;else throw new Error("Invalid username");this.config.password=typeof t.password=="string"?t.password:void 0,this.config.privateKey=typeof t.privateKey=="string"||Buffer.isBuffer(t.privateKey)?t.privateKey:void 0,this.config.localHostname=typeof t.localHostname=="string"?t.localHostname:void 0,this.config.localUsername=typeof t.localUsername=="string"?t.localUsername:void 0,this.config.tryKeyboard=t.tryKeyboard===!0,typeof t.agent=="string"&&t.agent.length?this.config.agent=kl(t.agent):Bl(t.agent)?this.config.agent=t.agent:this.config.agent=void 0,this.config.allowAgentFwd=t.agentForward===!0&&this.config.agent!==void 0;let s=this.config.authHandler=typeof t.authHandler=="function"||Array.isArray(t.authHandler)?t.authHandler:void 0;this.config.strictVendor=typeof t.strictVendor=="boolean"?t.strictVendor:!0;let i=this.config.debug=typeof t.debug=="function"?t.debug:void 0;if(t.agentForward===!0&&!this.config.allowAgentFwd)throw new Error("You must set a valid agent path to allow agent forwarding");let o=this._callbacks=[];this._chanMgr=new L0(this),this._forwarding={},this._forwardingUnix={},this._acceptX11=0,this._agentFwdEnabled=!1,this._agent=this.config.agent?this.config.agent:void 0,this._remoteVer=void 0;let a;if(this.config.privateKey){if(a=vs(this.config.privateKey,t.passphrase),a instanceof Error)throw new Error(`Cannot parse privateKey: ${a.message}`);if(Array.isArray(a)&&(a=a[0]),a.getPrivatePEM()===null)throw new Error("privateKey value does not contain a (valid) private key")}let c;if(typeof t.hostVerifier=="function"){let D=t.hostVerifier,v;y0.indexOf(t.hostHash)!==-1&&(v=t.hostHash),c=(N,H)=>{v&&(N=p0(v).update(N).digest("hex"));let X=D(N,H);X!==void 0&&H(X)}}let f=this._sock=t.sock||new A0,l=!1,u=!1;this._protocol&&this._protocol.cleanup();let h=i?(D,v,N)=>{i(`Debug output from server: ${JSON.stringify(N)}`)}:void 0,g,y=this._protocol=new B0({ident:this.config.ident,offer:r?void 0:e,onWrite:D=>{Pt(f)&&f.write(D)},onError:D=>{D.level==="handshake"&&clearTimeout(this._readyTimeout),y._destruct||f.removeAllListeners("data"),this.emit("error",D);try{f.end()}catch{}},onHeader:D=>{u=!0,this._remoteVer=D.versions.software,D.greeting&&this.emit("greeting",D.greeting)},onHandshakeComplete:D=>{this.emit("handshake",D),l||(l=!0,y.service("ssh-userauth"))},debug:i,hostVerifier:c,messageHandlers:{DEBUG:h,DISCONNECT:(D,v,N)=>{if(v!==Il.BY_APPLICATION){N||(N=x0[v],N===void 0&&(N=`Unexpected disconnection reason: ${v}`));let H=new Error(N);H.code=v,this.emit("error",H)}f.end()},SERVICE_ACCEPT:(D,v)=>{v==="ssh-userauth"&&Y()},EXT_INFO:(D,v)=>{if(g===void 0){for(let N of v)if(N.name==="server-sig-algs"){g=N.algs;return}g=null}},USERAUTH_BANNER:(D,v)=>{this.emit("banner",v)},USERAUTH_SUCCESS:D=>{k(),clearTimeout(this._readyTimeout),this.emit("ready")},USERAUTH_FAILURE:(D,v,N)=>{if(x.keyAlgos){let H=x.keyAlgos[0][0];if(i&&i(`Client: ${x.type} (${H}) auth failed`),x.keyAlgos.shift(),x.keyAlgos.length){let[X,fe]=x.keyAlgos[0];switch(x.type){case"agent":y.authPK(x.username,x.agentCtx.currentKey(),X);return;case"publickey":y.authPK(x.username,x.key,X);return;case"hostbased":y.authHostbased(x.username,x.key,x.localHostname,x.localUsername,X,(se,ze)=>{let _t=x.key.sign(se,fe);if(_t instanceof Error)return _t.message=`Error while signing with key: ${_t.message}`,_t.level="client-authentication",this.emit("error",_t),Y();ze(_t)});return}}else x.keyAlgos=void 0}if(x.type==="agent"){let H=x.agentCtx.pos();return i&&i(`Client: Agent key #${H+1} failed`),te()}i&&i(`Client: ${x.type} auth failed`),w=N,I=v,Y()},USERAUTH_PASSWD_CHANGEREQ:(D,v)=>{x.type==="password"&&this.emit("change password",v,N=>{y.authPassword(this.config.username,this.config.password,N)})},USERAUTH_PK_OK:D=>{let v,N;if(x.keyAlgos&&([v,N]=x.keyAlgos[0]),x.type==="agent"){let H=x.agentCtx.currentKey();y.authPK(x.username,H,v,(X,fe)=>{let se={hash:N};x.agentCtx.sign(H,X,se,(ze,_t)=>{if(ze)ze.level="agent",this.emit("error",ze);else return fe(_t);te()})})}else x.type==="publickey"&&y.authPK(x.username,x.key,v,(H,X)=>{let fe=x.key.sign(H,N);if(fe instanceof Error)return fe.message=`Error signing data with key: ${fe.message}`,fe.level="client-authentication",this.emit("error",fe),Y();X(fe)})},USERAUTH_INFO_REQUEST:(D,v,N,H)=>{if(x.type==="keyboard-interactive"){if((Array.isArray(H)?H.length:0)===0){i&&i("Client: Sending automatic USERAUTH_INFO_RESPONSE"),y.authInfoRes();return}x.prompt(v,N,"",H,fe=>{y.authInfoRes(fe)})}},REQUEST_SUCCESS:(D,v)=>{o.length&&o.shift()(!1,v)},REQUEST_FAILURE:D=>{o.length&&o.shift()(!0)},GLOBAL_REQUEST:(D,v,N,H)=>{v==="hostkeys-00@openssh.com"?(H0(this,H,(X,fe)=>{X||this.emit("hostkeys",fe)}),N&&y.requestSuccess()):N&&y.requestFailure()},CHANNEL_OPEN:(D,v)=>{$0(this,v)},CHANNEL_OPEN_CONFIRMATION:(D,v)=>{let N=this._chanMgr.get(v.recipient);if(typeof N!="function")return;let H=N.type==="sftp",fe={type:H?"session":N.type,incoming:{id:v.recipient,window:ks,packetSize:Bs,state:"open"},outgoing:{id:v.sender,window:v.window,packetSize:v.packetSize,state:"open"}},se=H?new R0(this,fe,{debug:i}):new Ml(this,fe);this._chanMgr.update(v.recipient,se),N(void 0,se)},CHANNEL_OPEN_FAILURE:(D,v,N,H)=>{let X=this._chanMgr.get(v);if(typeof X!="function")return;U0(this,v,{reason:N,description:H},X)},CHANNEL_DATA:(D,v,N)=>{let H=this._chanMgr.get(v);if(!(typeof H!="object"||H===null)&&H.incoming.window!==0){if(H.incoming.window-=N.length,H.push(N)===!1){H._waitChanDrain=!0;return}H.incoming.window<=Nl&&Rl(H)}},CHANNEL_EXTENDED_DATA:(D,v,N,H)=>{if(H!==b0)return;let X=this._chanMgr.get(v);if(!(typeof X!="object"||X===null)&&X.incoming.window!==0){if(X.incoming.window-=N.length,!X.stderr.push(N)){X._waitChanDrain=!0;return}X.incoming.window<=Nl&&Rl(X)}},CHANNEL_WINDOW_ADJUST:(D,v,N)=>{let H=this._chanMgr.get(v);typeof H!="object"||H===null||(H.outgoing.window+=N,H._waitWindow&&(H._waitWindow=!1,H._chunk?H._write(H._chunk,null,H._chunkcb):H._chunkcb?H._chunkcb():H._chunkErr?H.stderr._write(H._chunkErr,null,H._chunkcbErr):H._chunkcbErr&&H._chunkcbErr()))},CHANNEL_SUCCESS:(D,v)=>{let N=this._chanMgr.get(v);typeof N!="object"||N===null||(this._resetKA(),N._callbacks.length&&N._callbacks.shift()(!1))},CHANNEL_FAILURE:(D,v)=>{let N=this._chanMgr.get(v);typeof N!="object"||N===null||(this._resetKA(),N._callbacks.length&&N._callbacks.shift()(!0))},CHANNEL_REQUEST:(D,v,N,H,X)=>{let fe=this._chanMgr.get(v);if(typeof fe!="object"||fe===null)return;let se=fe._exit;if(se.code===void 0){switch(N){case"exit-status":fe.emit("exit",se.code=X);return;case"exit-signal":fe.emit("exit",se.code=null,se.signal=`SIG${X.signal}`,se.dump=X.coreDumped,se.desc=X.errorMessage);return}H&&D.channelFailure(fe.outgoing.id)}},CHANNEL_EOF:(D,v)=>{let N=this._chanMgr.get(v);typeof N!="object"||N===null||N.incoming.state==="open"&&(N.incoming.state="eof",N.readable&&N.push(null),N.stderr.readable&&N.stderr.push(null))},CHANNEL_CLOSE:(D,v)=>{D0(this,v,this._chanMgr.get(v))}}});f.pause();let _=this.config.keepaliveInterval,b=this.config.keepaliveCountMax,C=0,L,F=()=>{if(++C>b){if(clearInterval(L),f.readable){let D=new Error("Keepalive timeout");D.level="client-timeout",this.emit("error",D),f.destroy()}return}Pt(f)?(o.push(k),y.ping()):clearInterval(L)};function k(){_>0&&(C=0,clearInterval(L),Pt(f)&&(L=setInterval(F,_)))}this._resetKA=k;let K=(()=>{let D=!1;return()=>{if(!D&&(D=!0,O&&!u)){let v=N0("Connection lost before handshake","protocol",!0);this.emit("error",v)}}})(),ee=(()=>{let D=!1;return()=>{D||(D=!0,O=!0,i&&i("Socket connected"),this.emit("connect"),k0.then(()=>{y.start(),f.on("data",v=>{try{y.parse(v,0,v.length)}catch(N){this.emit("error",N);try{Pt(f)&&f.end()}catch{}}}),f.stderr&&typeof f.stderr.resume=="function"&&f.stderr.resume(),f.resume()}).catch(v=>{this.emit("error",v);try{Pt(f)&&f.end()}catch{}}))}})(),O=!1;f.on("connect",ee).on("timeout",()=>{this.emit("timeout")}).on("error",D=>{i&&i(`Socket error: ${D.message}`),clearTimeout(this._readyTimeout),D.level="client-socket",this.emit("error",D)}).on("end",()=>{i&&i("Socket ended"),K(),y.cleanup(),clearTimeout(this._readyTimeout),clearInterval(L),this.emit("end")}).on("close",()=>{i&&i("Socket closed"),K(),y.cleanup(),clearTimeout(this._readyTimeout),clearInterval(L),this.emit("close");let D=o;o=this._callbacks=[];let v=new Error("No response from server");for(let N=0;N<D.length;++N)D[N](v);this._chanMgr.cleanup(v)});let x,w=null,I=null,U=["none"];this.config.password!==void 0&&U.push("password"),a!==void 0&&U.push("publickey"),this._agent!==void 0&&U.push("agent"),this.config.tryKeyboard&&U.push("keyboard-interactive"),a!==void 0&&this.config.localHostname!==void 0&&this.config.localUsername!==void 0&&U.push("hostbased"),Array.isArray(s)?s=Ul(s):typeof s!="function"&&(s=Ul(U));let R=!1,re=D=>{if(!R){if(R=!0,D===!1){let v=new Error("All configured authentication methods failed");v.level="client-authentication",this.emit("error",v),this.end();return}if(typeof D=="string"){let v=D;if(U.indexOf(v)===-1)return G(`Authentication method not allowed: ${v}`);let N=this.config.username;switch(v){case"password":D={type:v,username:N,password:this.config.password};break;case"publickey":D={type:v,username:N,key:a};break;case"hostbased":D={type:v,username:N,key:a,localHostname:this.config.localHostname,localUsername:this.config.localUsername};break;case"agent":D={type:v,username:N,agentCtx:new vl(this._agent)};break;case"keyboard-interactive":D={type:v,username:N,prompt:(...H)=>this.emit("keyboard-interactive",...H)};break;case"none":D={type:v,username:N};break;default:return G(`Skipping unsupported authentication method: ${D}`)}}else{if(typeof D!="object"||D===null)return G(`Skipping invalid authentication attempt: ${D}`);{let v=D.username;if(typeof v!="string")return G(`Skipping invalid authentication attempt: ${D}`);let N=D.type;switch(N){case"password":{let{password:H}=D;if(typeof H!="string"&&!Buffer.isBuffer(H))return G("Skipping invalid password auth attempt");D={type:N,username:v,password:H};break}case"publickey":{let H=vs(D.key,D.passphrase);if(H instanceof Error)return G("Skipping invalid key auth attempt");if(!H.isPrivateKey())return G("Skipping non-private key");D={type:N,username:v,key:H};break}case"hostbased":{let{localHostname:H,localUsername:X}=D,fe=vs(D.key,D.passphrase);if(fe instanceof Error||typeof H!="string"||typeof X!="string")return G("Skipping invalid hostbased auth attempt");if(!fe.isPrivateKey())return G("Skipping non-private key");D={type:N,username:v,key:fe,localHostname:H,localUsername:X};break}case"agent":{let H=D.agent;if(typeof H=="string"&&H.length)H=kl(H);else if(!Bl(H))return G(`Skipping invalid agent: ${D.agent}`);D={type:N,username:v,agentCtx:new vl(H)};break}case"keyboard-interactive":{let{prompt:H}=D;if(typeof H!="function")return G("Skipping invalid keyboard-interactive auth attempt");D={type:N,username:v,prompt:H};break}case"none":D={type:N,username:v};break;default:return G(`Skipping unsupported authentication method: ${D}`)}}}x=D;try{let v=x.username;switch(x.type){case"password":y.authPassword(v,x.password);break;case"publickey":{let N;if(x.keyAlgos=Da(this,x.key,g),x.keyAlgos)if(x.keyAlgos.length)N=x.keyAlgos[0][0];else return G("Skipping key authentication (no mutual hash algorithm)");y.authPK(v,x.key,N);break}case"hostbased":{let N,H;if(x.keyAlgos=Da(this,x.key,g),x.keyAlgos)if(x.keyAlgos.length)[N,H]=x.keyAlgos[0];else return G("Skipping hostbased authentication (no mutual hash algorithm)");y.authHostbased(v,x.key,x.localHostname,x.localUsername,N,(X,fe)=>{let se=x.key.sign(X,H);if(se instanceof Error)return se.message=`Error while signing with key: ${se.message}`,se.level="client-authentication",this.emit("error",se),Y();fe(se)});break}case"agent":x.agentCtx.init(N=>{if(N)return N.level="agent",this.emit("error",N),Y();te()});break;case"keyboard-interactive":y.authKeyboard(v);break;case"none":y.authNone(v);break}}finally{R=!1}}};function G(D){i&&i(D),process.nextTick(Y)}function Y(){R=!1;let D=s(I,w,re);R||D===void 0||re(D)}let te=()=>{if(x.type==="agent"){let D=x.agentCtx.nextKey();if(D===!1)i&&i("Agent: No more keys left to try"),i&&i("Client: agent auth failed"),Y();else{let v=x.agentCtx.pos(),N;if(x.keyAlgos=Da(this,D,g),x.keyAlgos)if(x.keyAlgos.length)N=x.keyAlgos[0][0];else{i&&i(`Agent: Skipping key #${v+1} (no mutual hash algorithm)`),te();return}i&&i(`Agent: Trying key #${v+1}`),y.authPK(x.username,D,N)}}},ce=()=>{this.config.readyTimeout>0&&(this._readyTimeout=setTimeout(()=>{let D=new Error("Timed out while waiting for handshake");D.level="client-timeout",this.emit("error",D),f.destroy()},this.config.readyTimeout))};if(t.sock)ce(),typeof f.connecting=="boolean"&&f.connecting||ee();else{let D=this.config.host,v=this.config.forceIPv4,N=this.config.forceIPv6;i&&i(`Client: Trying ${D} on port ${this.config.port} ...`);let H=()=>{ce(),f.connect({host:D,port:this.config.port,localAddress:this.config.localAddress,localPort:this.config.localPort}),f.setMaxListeners(0),f.setTimeout(typeof t.timeout=="number"?t.timeout:0)};!v&&!N||v&&N?H():E0(D,v?4:6,(X,fe,se)=>{if(X){let ze=v?"IPv4":"IPv6",_t=new Error(`Error while looking up ${ze} address for '${D}': ${X}`);clearTimeout(this._readyTimeout),_t.level="client-dns",this.emit("error",_t),this.emit("close");return}D=fe,H()})}return this}end(){return this._sock&&Pt(this._sock)&&(this._protocol.disconnect(Il.BY_APPLICATION),this._sock.end()),this}destroy(){return this._sock&&Pt(this._sock)&&this._sock.destroy(),this}exec(t,e,r){if(!this._sock||!Pt(this._sock))throw new Error("Not connected");typeof e=="function"&&(r=e,e={});let s={allowHalfOpen:e.allowHalfOpen!==!1};return Mr(this,"session",s,(i,o)=>{if(i){r(i);return}let a=[];function c(f){if(f){o.close(),r(f);return}a.length&&a.shift()()}(this.config.allowAgentFwd===!0||e&&e.agentForward===!0&&this._agent!==void 0)&&a.push(()=>Ll(o,c)),typeof e=="object"&&e!==null&&(typeof e.env=="object"&&e.env!==null&&La(o,e.env),(typeof e.pty=="object"&&e.pty!==null||e.pty===!0)&&a.push(()=>Tl(o,e.pty,c)),(typeof e.x11=="object"&&e.x11!==null||e.x11==="number"||e.x11===!0)&&a.push(()=>Pl(o,e.x11,c))),a.push(()=>M0(o,t,e,r)),a.shift()()}),this}shell(t,e,r){if(!this._sock||!Pt(this._sock))throw new Error("Not connected");return typeof t=="function"?(r=t,t=e=void 0):typeof e=="function"&&(r=e,e=void 0),t&&(t.x11!==void 0||t.env!==void 0)&&(e=t,t=void 0),Mr(this,"session",(s,i)=>{if(s){r(s);return}let o=[];function a(c){if(c){i.close(),r(c);return}o.length&&o.shift()()}(this.config.allowAgentFwd===!0||e&&e.agentForward===!0&&this._agent!==void 0)&&o.push(()=>Ll(i,a)),t!==!1&&o.push(()=>Tl(i,t,a)),typeof e=="object"&&e!==null&&(typeof e.env=="object"&&e.env!==null&&La(i,e.env),(typeof e.x11=="object"&&e.x11!==null||e.x11==="number"||e.x11===!0)&&o.push(()=>Pl(i,e.x11,a))),o.push(()=>O0(i,r)),o.shift()()}),this}subsys(t,e){if(!this._sock||!Pt(this._sock))throw new Error("Not connected");return Mr(this,"session",(r,s)=>{if(r){e(r);return}Ua(s,t,(i,o)=>{if(i){e(i);return}e(void 0,o)})}),this}forwardIn(t,e,r){if(!this._sock||!Pt(this._sock))throw new Error("Not connected");let s=typeof r=="function";return s&&this._callbacks.push((i,o)=>{if(i){r(i!==!0?i:new Error(`Unable to bind to ${t}:${e}`));return}let a=e;e===0&&o&&o.length>=4&&(a=P0(o,0),this._protocol._compatFlags&Dl.DYN_RPORT_BUG||(e=a)),this._forwarding[`${t}:${e}`]=a,r(void 0,a)}),this._protocol.tcpipForward(t,e,s),this}unforwardIn(t,e,r){if(!this._sock||!Pt(this._sock))throw new Error("Not connected");let s=typeof r=="function";return s&&this._callbacks.push(i=>{if(i){r(i!==!0?i:new Error(`Unable to unbind from ${t}:${e}`));return}delete this._forwarding[`${t}:${e}`],r()}),this._protocol.cancelTcpipForward(t,e,s),this}forwardOut(t,e,r,s,i){if(!this._sock||!Pt(this._sock))throw new Error("Not connected");let o={srcIP:t,srcPort:e,dstIP:r,dstPort:s};return typeof i!="function"&&(i=Oa),Mr(this,"direct-tcpip",o,i),this}openssh_noMoreSessions(t){if(!this._sock||!Pt(this._sock))throw new Error("Not connected");let e=typeof t=="function";return!this.config.strictVendor||this.config.strictVendor&&Ci.test(this._remoteVer)?(e&&this._callbacks.push(r=>{if(r){t(r!==!0?r:new Error("Unable to disable future sessions"));return}t()}),this._protocol.openssh_noMoreSessions(e),this):e?(process.nextTick(t,new Error("strictVendor enabled and server is not OpenSSH or compatible version")),this):this}openssh_forwardInStreamLocal(t,e){if(!this._sock||!Pt(this._sock))throw new Error("Not connected");let r=typeof e=="function";return!this.config.strictVendor||this.config.strictVendor&&Ci.test(this._remoteVer)?(r&&this._callbacks.push(s=>{if(s){e(s!==!0?s:new Error(`Unable to bind to ${t}`));return}this._forwardingUnix[t]=!0,e()}),this._protocol.openssh_streamLocalForward(t,r),this):r?(process.nextTick(e,new Error("strictVendor enabled and server is not OpenSSH or compatible version")),this):this}openssh_unforwardInStreamLocal(t,e){if(!this._sock||!Pt(this._sock))throw new Error("Not connected");let r=typeof e=="function";return!this.config.strictVendor||this.config.strictVendor&&Ci.test(this._remoteVer)?(r&&this._callbacks.push(s=>{if(s){e(s!==!0?s:new Error(`Unable to unbind from ${t}`));return}delete this._forwardingUnix[t],e()}),this._protocol.openssh_cancelStreamLocalForward(t,r),this):r?(process.nextTick(e,new Error("strictVendor enabled and server is not OpenSSH or compatible version")),this):this}openssh_forwardOutStreamLocal(t,e){if(!this._sock||!Pt(this._sock))throw new Error("Not connected");return typeof e!="function"&&(e=Oa),!this.config.strictVendor||this.config.strictVendor&&Ci.test(this._remoteVer)?(Mr(this,"direct-streamlocal@openssh.com",{socketPath:t},e),this):(process.nextTick(e,new Error("strictVendor enabled and server is not OpenSSH or compatible version")),this)}sftp(t,e){if(!this._sock||!Pt(this._sock))throw new Error("Not connected");return typeof t=="function"&&(e=t,t=void 0),Mr(this,"sftp",(r,s)=>{if(r){e(r);return}let i=(o,a)=>{if(o){e(o);return}function c(){s.removeListener("ready",f),s.removeListener("error",l),s.removeListener("exit",u),s.removeListener("close",u)}function f(){c(),e(void 0,s)}function l(h){c(),e(h)}function u(h,g){c();let y;typeof h=="number"?y=`Received exit code ${h} while establishing SFTP session`:g!==void 0?y=`Received signal ${g} while establishing SFTP session`:y="Received unexpected SFTP session termination";let _=new Error(y);_.code=h,_.signal=g,e(_)}s.on("ready",f).on("error",l).on("exit",u).on("close",u),s._init()};typeof t=="object"&&t!==null?La(s,t,o=>{if(o){e(o);return}Ua(s,"sftp",i)}):Ua(s,"sftp",i)}),this}setNoDelay(t){return this._sock&&typeof this._sock.setNoDelay=="function"&&this._sock.setNoDelay(t),this}};function Mr(n,t,e,r){let s=ks,i=Bs;typeof e=="function"&&(r=e,e={});let o=(c,f)=>{r(c,f)};o.type=t;let a=n._chanMgr.add(o);if(a===-1){r(new Error("No free channels available"));return}switch(t){case"session":case"sftp":n._protocol.session(a,s,i);break;case"direct-tcpip":n._protocol.directTcpip(a,s,i,e);break;case"direct-streamlocal@openssh.com":n._protocol.openssh_directStreamLocal(a,s,i,e);break;default:throw new Error(`Unsupported channel type: ${t}`)}}function Pl(n,t,e){let r={single:!1,protocol:"MIT-MAGIC-COOKIE-1",cookie:void 0,screen:0};typeof t=="function"?e=t:typeof t=="object"&&t!==null&&(typeof t.single=="boolean"&&(r.single=t.single),typeof t.screen=="number"&&(r.screen=t.screen),typeof t.protocol=="string"&&(r.protocol=t.protocol),typeof t.cookie=="string"?r.cookie=t.cookie:Buffer.isBuffer(t.cookie)&&(r.cookie=t.cookie.hexSlice(0,t.cookie.length))),r.cookie===void 0&&(r.cookie=F0());let s=typeof e=="function";if(n.outgoing.state!=="open"){s&&e(new Error("Channel is not open"));return}s&&n._callbacks.push(i=>{if(i){e(i!==!0?i:new Error("Unable to request X11"));return}n._hasX11=!0,++n._client._acceptX11,n.once("close",()=>{n._client._acceptX11&&--n._client._acceptX11}),e()}),n._client._protocol.x11Forward(n.outgoing.id,r,s)}function Tl(n,t,e){let r=24,s=80,i=640,o=480,a="vt100",c=null;typeof t=="function"?e=t:typeof t=="object"&&t!==null&&(typeof t.rows=="number"&&(r=t.rows),typeof t.cols=="number"&&(s=t.cols),typeof t.width=="number"&&(i=t.width),typeof t.height=="number"&&(o=t.height),typeof t.term=="string"&&(a=t.term),typeof t.modes=="object"&&(c=t.modes));let f=typeof e=="function";if(n.outgoing.state!=="open"){f&&e(new Error("Channel is not open"));return}f&&n._callbacks.push(l=>{if(l){e(l!==!0?l:new Error("Unable to request a pseudo-terminal"));return}e()}),n._client._protocol.pty(n.outgoing.id,r,s,o,i,a,c,f)}function Ll(n,t){let e=typeof t=="function";if(n.outgoing.state!=="open"){e&&t(new Error("Channel is not open"));return}if(n._client._agentFwdEnabled){e&&t(!1);return}n._client._agentFwdEnabled=!0,n._callbacks.push(r=>{if(r){n._client._agentFwdEnabled=!1,e&&t(r!==!0?r:new Error("Unable to request agent forwarding"));return}e&&t()}),n._client._protocol.openssh_agentForward(n.outgoing.id,!0)}function O0(n,t){if(n.outgoing.state!=="open"){t(new Error("Channel is not open"));return}n._callbacks.push(e=>{if(e){t(e!==!0?e:new Error("Unable to open shell"));return}n.subtype="shell",t(void 0,n)}),n._client._protocol.shell(n.outgoing.id,!0)}function M0(n,t,e,r){if(n.outgoing.state!=="open"){r(new Error("Channel is not open"));return}n._callbacks.push(s=>{if(s){r(s!==!0?s:new Error("Unable to exec"));return}n.subtype="exec",n.allowHalfOpen=e.allowHalfOpen!==!1,r(void 0,n)}),n._client._protocol.exec(n.outgoing.id,t,!0)}function La(n,t,e){let r=typeof e=="function";if(n.outgoing.state!=="open"){r&&e(new Error("Channel is not open"));return}r&&n._callbacks.push(i=>{if(i){e(i!==!0?i:new Error("Unable to set environment"));return}e()});let s=Object.keys(t||{});for(let i=0;i<s.length;++i){let o=s[i],a=t[o];n._client._protocol.env(n.outgoing.id,o,a,r)}}function Ua(n,t,e){if(n.outgoing.state!=="open"){e(new Error("Channel is not open"));return}n._callbacks.push(r=>{if(r){e(r!==!0?r:new Error(`Unable to start subsystem: ${t}`));return}n.subtype="subsystem",e(void 0,n)}),n._client._protocol.subsystem(n.outgoing.id,t,!0)}function $0(n,t){let e=-1,r,s=()=>{let c={type:t.type,incoming:{id:e,window:ks,packetSize:Bs,state:"open"},outgoing:{id:t.sender,window:t.window,packetSize:t.packetSize,state:"open"}},f=new Ml(n,c);return n._chanMgr.update(e,f),n._protocol.channelOpenConfirm(t.sender,e,ks,Bs),f},i=()=>{r===void 0&&(e===-1?r=wi.RESOURCE_SHORTAGE:r=wi.CONNECT_FAILED),e!==-1&&n._chanMgr.remove(e),n._protocol.channelOpenFail(t.sender,r,"")},o=()=>(e=n._chanMgr.add(),e===-1&&(r=wi.RESOURCE_SHORTAGE,n.config.debug&&n.config.debug("Client: Automatic rejection of incoming channel open: no channels available")),e!==-1),a=t.data;switch(t.type){case"forwarded-tcpip":{let c=n._forwarding[`${a.destIP}:${a.destPort}`];if(c!==void 0&&o()){a.destPort===0&&(a.destPort=c),n.emit("tcp connection",a,s,i);return}break}case"forwarded-streamlocal@openssh.com":if(n._forwardingUnix[a.socketPath]!==void 0&&o()){n.emit("unix connection",a,s,i);return}break;case"auth-agent@openssh.com":if(n._agentFwdEnabled&&typeof n._agent.getStream=="function"&&o()){n._agent.getStream((c,f)=>{if(c)return i();let l=s();l.pipe(f).pipe(l)});return}break;case"x11":if(n._acceptX11!==0&&o()){n.emit("x11",a,s,i);return}break;default:r=wi.UNKNOWN_CHANNEL_TYPE,n.config.debug&&n.config.debug(`Client: Automatic rejection of unsupported incoming channel open type: ${t.type}`)}r===void 0&&(r=wi.ADMINISTRATIVELY_PROHIBITED,n.config.debug&&n.config.debug("Client: Automatic rejection of unexpected incoming channel open for: "+t.type)),i()}var F0=(()=>{let n=Buffer.allocUnsafe(16);return()=>(m0(n,0,16),n.hexSlice(0,16))})();function Ul(n){if(!Array.isArray(n))throw new Error("authList must be an array");let t=0;return(e,r,s)=>t===n.length?!1:n[t++]}function H0(n,t,e){if(!n._sock||!Pt(n._sock))return;if(typeof e!="function"&&(e=Oa),!Array.isArray(t))throw new TypeError("Invalid keys argument type");let r=[];for(let s of t){let i=vs(s);if(i instanceof Error)throw i;r.push(i)}if(!n.config.strictVendor||n.config.strictVendor&&Ci.test(n._remoteVer)){n._callbacks.push((s,i)=>{if(s){e(s!==!0?s:new Error("Server failed to prove supplied keys"));return}let o=[],a=0;for(Is.init(i,0);Is.avail()&&a!==r.length;){let c=r[a++],f=c.getPublicSSH(),l=Is.readString();Cs.init(l,0);let u=Cs.readString(!0),h=Cs.readString(),g;if(u!==c.type)if(c.type==="ssh-rsa")switch(u){case"rsa-sha2-256":g="sha256";break;case"rsa-sha2-512":g="sha512";break;default:continue}else continue;let y=n._protocol._kex.sessionID,_=Buffer.allocUnsafe(37+y.length+4+f.length),b=0;Ta(_,29,b),_.utf8Write("hostkeys-prove-00@openssh.com",b+=4,29),Ta(_,y.length,b+=29),Cl(y,_,0,y.length,b+=4),Ta(_,f.length,b+=y.length),Cl(f,_,0,f.length,b+=4),(h=T0(h,u))&&c.verify(_,h,g)===!0&&o.push(c)}Cs.clear(),Is.clear(),e(null,o)}),n._protocol.openssh_hostKeysProve(r);return}process.nextTick(e,new Error("strictVendor enabled and server is not OpenSSH or compatible version"))}function Da(n,t,e){switch(t.type){case"ssh-rsa":if(n._protocol._compatFlags&Dl.IMPLY_RSA_SHA2_SIGALGS&&(Array.isArray(e)?e=["rsa-sha2-256","rsa-sha2-512",...e]:e=["rsa-sha2-256","rsa-sha2-512"]),Array.isArray(e)){if(e.indexOf("rsa-sha2-256")!==-1)return[["rsa-sha2-256","sha256"]];if(e.indexOf("rsa-sha2-512")!==-1)return[["rsa-sha2-512","sha512"]];if(e.indexOf("ssh-rsa")===-1)return[]}return[["ssh-rsa","sha1"]]}}$l.exports=Ma});var Hl=at(Fl=>{"use strict";var{Agent:Ha}=require("http"),{Agent:Q0}=require("https"),{connect:W0}=require("tls"),Fa;for(let n of[Ha,Q0]){class t extends n{constructor(r,s){super(s),this._connectCfg=r,this._defaultSrcIP=s&&s.srcIP||"localhost"}createConnection(r,s){let i=r&&r.localAddress||this._defaultSrcIP,o=r&&r.localPort||0,a=r.host,c=r.port;Fa===void 0&&(Fa=$a());let f=new Fa,l=!1;f.on("ready",()=>{f.forwardOut(i,o,a,c,(u,h)=>{if(l=!0,u)return f.end(),s(u);h.once("close",()=>f.end()),s(null,q0(h,n,r))})}).on("error",s).on("close",()=>{l||s(new Error("Unexpected connection close"))}).connect(this._connectCfg)}}Fl[n===Ha?"SSHTTPAgent":"SSHTTPSAgent"]=t}function vi(){}function q0(n,t,e){if(t===Ha)return n.setKeepAlive=vi,n.setNoDelay=vi,n.setTimeout=vi,n.ref=vi,n.unref=vi,n.destroySoon=n.destroy,n;e.socket=n;let r=W0(e),s=(()=>{let i=!1;return()=>{i||(i=!0,n.isPaused()&&n.resume())}})();return r.on("end",s).on("close",s),r}});var Wl=at((NE,Ka)=>{"use strict";var{Server:K0}=require("net"),Bi=require("events"),{listenerCount:Kt}=Bi,{CHANNEL_OPEN_FAILURE:$r,DEFAULT_CIPHER:V0,DEFAULT_COMPRESSION:G0,DEFAULT_KEX:Y0,DEFAULT_MAC:z0,DEFAULT_SERVER_HOST_KEY:j0,DISCONNECT_REASON:Fr,DISCONNECT_REASON_BY_VALUE:X0,SUPPORTED_CIPHER:J0,SUPPORTED_COMPRESSION:Z0,SUPPORTED_KEX:em,SUPPORTED_MAC:tm,SUPPORTED_SERVER_HOST_KEY:nm}=Pn(),{init:rm}=Qn(),{KexInit:im}=ds(),{parseKey:Ql}=Kn(),sm=ha(),{SFTP:om}=bi(),{writeUInt32BE:am}=dn(),{Channel:Hr,MAX_WINDOW:Yn,PACKET_SIZE:zn,windowAdjust:cm,WINDOW_THRESHOLD:fm}=Ba(),{ChannelManager:lm,generateAlgorithmList:ki,isWritable:Rs,onChannelOpenFailure:um,onCHANNEL_CLOSE:dm}=Pa(),hm=10,jn=class extends Bi{constructor(t,e,r,s,i){super(),this.username=this.user=e,this.service=r,this.method=s,this._initialResponse=!1,this._finalResponse=!1,this._multistep=!1,this._cbfinal=(o,a,c)=>{this._finalResponse||(this._finalResponse=!0,i(this,o,a,c))},this._protocol=t}accept(){this._cleanup&&this._cleanup(),this._initialResponse=!0,this._cbfinal(!0)}reject(t,e){this._cleanup&&this._cleanup(),this._initialResponse=!0,this._cbfinal(!1,t,e)}},Ns=class extends jn{constructor(t,e,r,s,i,o){super(t,e,r,s,o),this._multistep=!0,this._cb=void 0,this._onInfoResponse=a=>{let c=this._cb;c&&(this._cb=void 0,c(a))},this.submethods=i,this.on("abort",()=>{this._cb&&this._cb(new Error("Authentication request aborted"))})}prompt(t,e,r,s){Array.isArray(t)||(t=[t]),typeof e=="function"?(s=e,e=r=void 0):typeof r=="function"?(s=r,r=void 0):typeof s!="function"&&(s=void 0);for(let i=0;i<t.length;++i)typeof t[i]=="string"&&(t[i]={prompt:t[i],echo:!0});this._cb=s,this._initialResponse=!0,this._protocol.authInfoReq(e,r,t)}},Wa=class extends jn{constructor(t,e,r,s,i,o){super(t,e,r,s,o),this.key={algo:i.keyAlgo,data:i.key},this.hashAlgo=i.hashAlgo,this.signature=i.signature,this.blob=i.blob}accept(){this.signature?jn.prototype.accept.call(this):(this._initialResponse=!0,this._protocol.authPKOK(this.key.algo,this.key.data))}},qa=class extends jn{constructor(t,e,r,s,i,o){super(t,e,r,s,o),this.key={algo:i.keyAlgo,data:i.key},this.hashAlgo=i.hashAlgo,this.signature=i.signature,this.blob=i.blob,this.localHostname=i.localHostname,this.localUsername=i.localUsername}},Ps=class extends jn{constructor(t,e,r,s,i,o){super(t,e,r,s,o),this.password=i,this._changeCb=void 0}requestChange(t,e){if(this._changeCb)throw new Error("Change request already in progress");if(typeof t!="string")throw new Error("prompt argument must be a string");if(typeof e!="function")throw new Error("Callback argument must be a function");this._changeCb=e,this._protocol.authPasswdChg(t)}},bn=class extends Bi{constructor(t,e,r){super(),this.type="session",this.subtype=void 0,this.server=!0,this._ending=!1,this._channel=void 0,this._chanInfo={type:"session",incoming:{id:r,window:Yn,packetSize:zn,state:"open"},outgoing:{id:e.sender,window:e.window,packetSize:e.packetSize,state:"open"}}}},sn=class extends Bi{constructor(t,e){if(super(),typeof t!="object"||t===null)throw new Error("Missing configuration object");let r=Object.create(null),s=[],i=t.hostKeys;if(!Array.isArray(i))throw new Error("hostKeys must be an array");let o=typeof t.algorithms=="object"&&t.algorithms!==null?t.algorithms:{},a=ki(o.serverHostKey,j0,nm);for(let h=0;h<i.length;++h){let g;if(Buffer.isBuffer(i[h])||typeof i[h]=="string"?g=Ql(i[h]):g=Ql(i[h].key,i[h].passphrase),g instanceof Error)throw new Error(`Cannot parse privateKey: ${g.message}`);if(Array.isArray(g)&&(g=g[0]),g.getPrivatePEM()===null)throw new Error("privateKey value contains an invalid private key");if(!s.includes(g.type))if(g.type==="ssh-rsa"){let y=a.indexOf("ssh-rsa"),_=a.indexOf("rsa-sha2-256"),b=a.indexOf("rsa-sha2-512");y===-1&&(y=1/0),[y,_,b].sort(pm).forEach(C=>{if(C===-1)return;let L;switch(C){case y:L="ssh-rsa";break;case _:L="rsa-sha2-256";break;case b:L="rsa-sha2-512";break;default:return}r[L]=g,s.push(L)})}else r[g.type]=g,s.push(g.type)}let c={kex:ki(o.kex,Y0,em).concat(["kex-strict-s-v00@openssh.com"]),serverHostKey:s,cs:{cipher:ki(o.cipher,V0,J0),mac:ki(o.hmac,z0,tm),compress:ki(o.compress,G0,Z0),lang:[]},sc:void 0};c.sc=c.cs,typeof e=="function"&&this.on("connection",e);let f=typeof t.debug=="function"?t.debug:void 0,l=t.ident?Buffer.from(t.ident):void 0,u=new im(c);this._srv=new K0(h=>{if(this._connections>=this.maxConnections){h.destroy();return}++this._connections,h.once("close",()=>{--this._connections});let g;if(f){let y=`[${process.hrtime().join(".")}] `;g=_=>{f(`${y}${_}`)}}new Ts(h,r,l,u,g,this,t)}).on("error",h=>{this.emit("error",h)}).on("listening",()=>{this.emit("listening")}).on("close",()=>{this.emit("close")}),this._connections=0,this.maxConnections=1/0}injectSocket(t){this._srv.emit("connection",t)}listen(...t){return this._srv.listen(...t),this}address(){return this._srv.address()}getConnections(t){return this._srv.getConnections(t),this}close(t){return this._srv.close(t),this}ref(){return this._srv.ref(),this}unref(){return this._srv.unref(),this}};sn.KEEPALIVE_CLIENT_INTERVAL=15e3;sn.KEEPALIVE_CLIENT_COUNT_MAX=3;var Ts=class extends Bi{constructor(t,e,r,s,i,o,a){super();let c=0,f=!1,l=[],u,h,g,y=[];this._sock=t,this._chanMgr=new lm(this),this._debug=i,this.noMoreSessions=!1,this.authenticated=!1;function _(O){}this.on("error",_);let b=i?(O,x,w)=>{i(`Debug output from client: ${JSON.stringify(w)}`)}:void 0,C=typeof a.keepaliveInterval=="number"&&isFinite(a.keepaliveInterval)&&a.keepaliveInterval>0?a.keepaliveInterval:typeof sn.KEEPALIVE_CLIENT_INTERVAL=="number"&&isFinite(sn.KEEPALIVE_CLIENT_INTERVAL)&&sn.KEEPALIVE_CLIENT_INTERVAL>0?sn.KEEPALIVE_CLIENT_INTERVAL:-1,L=typeof a.keepaliveCountMax=="number"&&isFinite(a.keepaliveCountMax)&&a.keepaliveCountMax>=0?a.keepaliveCountMax:typeof sn.KEEPALIVE_CLIENT_COUNT_MAX=="number"&&isFinite(sn.KEEPALIVE_CLIENT_COUNT_MAX)&&sn.KEEPALIVE_CLIENT_COUNT_MAX>=0?sn.KEEPALIVE_CLIENT_COUNT_MAX:-1,F=0;C!==-1&&L!==-1&&(this.once("ready",()=>{let O=()=>{clearInterval(h)};this.on("close",O).on("end",O),h=setInterval(()=>{if(++F>L){clearInterval(h);let x=new Error("Keepalive timeout");x.level="client-timeout",this.emit("error",x),this.end()}else k.ping()},C)}),g=()=>{h&&h.refresh(),F=0});let k=this._protocol=new sm({server:!0,hostKeys:e,ident:r,offer:s,onPacket:g,greeting:a.greeting,banner:a.banner,onWrite:O=>{Rs(t)&&t.write(O)},onError:O=>{k._destruct||t.removeAllListeners("data"),this.emit("error",O);try{t.end()}catch{}},onHeader:O=>{this.removeListener("error",_);let x={ip:t.remoteAddress,family:t.remoteFamily,port:t.remotePort,header:O};if(!o.emit("connection",this,x)){k.disconnect(Fr.BY_APPLICATION),t.end();return}O.greeting&&this.emit("greeting",O.greeting)},onHandshakeComplete:O=>{++c>1&&this.emit("rekey"),this.emit("handshake",O)},debug:i,messageHandlers:{DEBUG:b,DISCONNECT:(O,x,w)=>{if(x!==Fr.BY_APPLICATION){w||(w=X0[x],w===void 0&&(w=`Unexpected disconnection reason: ${x}`));let I=new Error(w);I.code=x,this.emit("error",I)}t.end()},CHANNEL_OPEN:(O,x)=>{if(x.type==="session"&&this.noMoreSessions||!this.authenticated){let te=$r.ADMINISTRATIVELY_PROHIBITED;return k.channelOpenFail(x.sender,te)}let w=-1,I,U=!1,R,re=()=>{U||(U=!0,I===void 0&&(w===-1?I=$r.RESOURCE_SHORTAGE:I=$r.CONNECT_FAILED),w!==-1&&this._chanMgr.remove(w),k.channelOpenFail(x.sender,I,""))},G=()=>(w=this._chanMgr.add(),w===-1&&(I=$r.RESOURCE_SHORTAGE,i&&i("Automatic rejection of incoming channel open: no channels available")),w!==-1),Y=x.data;switch(x.type){case"session":if(Kt(this,"session")&&G()){R=()=>{if(U)return;U=!0;let te=new bn(this,x,w);return this._chanMgr.update(w,te),k.channelOpenConfirm(x.sender,w,Yn,zn),te},this.emit("session",R,re);return}break;case"direct-tcpip":if(Kt(this,"tcpip")&&G()){R=()=>{if(U)return;U=!0;let te={type:void 0,incoming:{id:w,window:Yn,packetSize:zn,state:"open"},outgoing:{id:x.sender,window:x.window,packetSize:x.packetSize,state:"open"}},ce=new Hr(this,te,{server:!0});return this._chanMgr.update(w,ce),k.channelOpenConfirm(x.sender,w,Yn,zn),ce},this.emit("tcpip",R,re,Y);return}break;case"direct-streamlocal@openssh.com":if(Kt(this,"openssh.streamlocal")&&G()){R=()=>{if(U)return;U=!0;let te={type:void 0,incoming:{id:w,window:Yn,packetSize:zn,state:"open"},outgoing:{id:x.sender,window:x.window,packetSize:x.packetSize,state:"open"}},ce=new Hr(this,te,{server:!0});return this._chanMgr.update(w,ce),k.channelOpenConfirm(x.sender,w,Yn,zn),ce},this.emit("openssh.streamlocal",R,re,Y);return}break;default:I=$r.UNKNOWN_CHANNEL_TYPE,i&&i(`Automatic rejection of unsupported incoming channel open type: ${x.type}`)}I===void 0&&(I=$r.ADMINISTRATIVELY_PROHIBITED,i&&i(`Automatic rejection of unexpected incoming channel open for: ${x.type}`)),re()},CHANNEL_OPEN_CONFIRMATION:(O,x)=>{let w=this._chanMgr.get(x.recipient);if(typeof w!="function")return;let I={type:w.type,incoming:{id:x.recipient,window:Yn,packetSize:zn,state:"open"},outgoing:{id:x.sender,window:x.window,packetSize:x.packetSize,state:"open"}},U=new Hr(this,I,{server:!0});this._chanMgr.update(x.recipient,U),w(void 0,U)},CHANNEL_OPEN_FAILURE:(O,x,w,I)=>{let U=this._chanMgr.get(x);if(typeof U!="function")return;um(this,x,{reason:w,description:I},U)},CHANNEL_DATA:(O,x,w)=>{let I=this._chanMgr.get(x);if(!(typeof I!="object"||I===null)&&!(I.constructor===bn&&(I=I._channel,!I))&&I.incoming.window!==0){if(I.incoming.window-=w.length,I.push(w)===!1){I._waitChanDrain=!0;return}I.incoming.window<=fm&&cm(I)}},CHANNEL_EXTENDED_DATA:(O,x,w,I)=>{},CHANNEL_WINDOW_ADJUST:(O,x,w)=>{let I=this._chanMgr.get(x);typeof I!="object"||I===null||I.constructor===bn&&(I=I._channel,!I)||(I.outgoing.window+=w,I._waitWindow&&(I._waitWindow=!1,I._chunk?I._write(I._chunk,null,I._chunkcb):I._chunkcb?I._chunkcb():I._chunkErr?I.stderr._write(I._chunkErr,null,I._chunkcbErr):I._chunkcbErr&&I._chunkcbErr()))},CHANNEL_SUCCESS:(O,x)=>{let w=this._chanMgr.get(x);typeof w!="object"||w===null||w.constructor===bn&&(w=w._channel,!w)||w._callbacks.length&&w._callbacks.shift()(!1)},CHANNEL_FAILURE:(O,x)=>{let w=this._chanMgr.get(x);typeof w!="object"||w===null||w.constructor===bn&&(w=w._channel,!w)||w._callbacks.length&&w._callbacks.shift()(!0)},CHANNEL_REQUEST:(O,x,w,I,U)=>{let R=this._chanMgr.get(x);if(typeof R!="object"||R===null)return;let re=!1,G,Y;if(R.constructor!==bn){I&&k.channelFailure(R.outgoing.id);return}if(I&&(w!=="shell"&&w!=="exec"&&w!=="subsystem"&&(G=()=>{re||R._ending||R._channel||(re=!0,k.channelSuccess(R._chanInfo.outgoing.id))}),Y=()=>{re||R._ending||R._channel||(re=!0,k.channelFailure(R._chanInfo.outgoing.id))}),R._ending){Y&&Y();return}switch(w){case"env":if(Kt(R,"env")){R.emit("env",G,Y,{key:U.name,val:U.value});return}break;case"pty-req":if(Kt(R,"pty")){R.emit("pty",G,Y,U);return}break;case"window-change":Kt(R,"window-change")?R.emit("window-change",G,Y,U):Y&&Y();break;case"x11-req":if(Kt(R,"x11")){R.emit("x11",G,Y,U);return}break;case"signal":if(Kt(R,"signal")){R.emit("signal",G,Y,{name:U});return}break;case"auth-agent-req@openssh.com":if(Kt(R,"auth-agent")){R.emit("auth-agent",G,Y);return}break;case"shell":if(Kt(R,"shell")){G=()=>{if(re||R._ending||R._channel)return;re=!0,I&&k.channelSuccess(R._chanInfo.outgoing.id);let te=new Hr(this,R._chanInfo,{server:!0});return te.subtype=R.subtype=w,R._channel=te,te},R.emit("shell",G,Y);return}break;case"exec":if(Kt(R,"exec")){G=()=>{if(re||R._ending||R._channel)return;re=!0,I&&k.channelSuccess(R._chanInfo.outgoing.id);let te=new Hr(this,R._chanInfo,{server:!0});return te.subtype=R.subtype=w,R._channel=te,te},R.emit("exec",G,Y,{command:U});return}break;case"subsystem":{let te=U==="sftp";if(G=()=>{if(re||R._ending||R._channel)return;re=!0,I&&k.channelSuccess(R._chanInfo.outgoing.id);let ce;return te?ce=new om(this,R._chanInfo,{server:!0,debug:i}):(ce=new Hr(this,R._chanInfo,{server:!0}),ce.subtype=R.subtype=`${w}:${U}`),R._channel=ce,ce},U==="sftp"){if(Kt(R,"sftp")){R.emit("sftp",G,Y);return}te=!1}if(Kt(R,"subsystem")){R.emit("subsystem",G,Y,{name:U});return}break}}i&&i(`Automatic rejection of incoming channel request: ${w}`),Y&&Y()},CHANNEL_EOF:(O,x)=>{let w=this._chanMgr.get(x);typeof w!="object"||w===null||w.constructor===bn&&(w._ending||(w._ending=!0,w.emit("eof"),w.emit("end")),w=w._channel,!w)||w.incoming.state==="open"&&(w.incoming.state="eof",w.readable&&w.push(null))},CHANNEL_CLOSE:(O,x)=>{let w=this._chanMgr.get(x);typeof w!="object"||w===null||w.constructor===bn&&(w._ending=!0,w.emit("close"),w=w._channel,!w)||dm(this,x,w)},SERVICE_REQUEST:(O,x)=>{if(c===0||f||this.authenticated||x!=="ssh-userauth"){k.disconnect(Fr.SERVICE_NOT_AVAILABLE),t.end();return}f=!0,k.serviceAccept(x)},USERAUTH_REQUEST:(O,x,w,I,U)=>{if(c===0||this.authenticated||u&&(u.username!==x||u.service!==w)||I!=="password"&&I!=="publickey"&&I!=="hostbased"&&I!=="keyboard-interactive"&&I!=="none"||l.length===hm){k.disconnect(Fr.PROTOCOL_ERROR),t.end();return}else if(w!=="ssh-connection"){k.disconnect(Fr.SERVICE_NOT_AVAILABLE),t.end();return}let R;switch(I){case"keyboard-interactive":R=new Ns(k,x,w,I,U,K);break;case"publickey":R=new Wa(k,x,w,I,U,K);break;case"hostbased":R=new qa(k,x,w,I,U,K);break;case"password":if(u&&u instanceof Ps&&u._changeCb){let re=u._changeCb;u._changeCb=void 0,re(U.newPassword);return}R=new Ps(k,x,w,I,U,K);break;case"none":R=new jn(k,x,w,I,K);break}if(u)if(u._initialResponse)u._multistep&&!u._finalResponse&&(u._cleanup&&u._cleanup(),u.emit("abort"));else return l.push(R);u=R,Kt(this,"authentication")?this.emit("authentication",u):u.reject()},USERAUTH_INFO_RESPONSE:(O,x)=>{u&&u instanceof Ns&&u._onInfoResponse(x)},GLOBAL_REQUEST:(O,x,w,I)=>{let U={type:null,buf:null};function R(re,G){U.type=re,U.buf=G,ee()}if(w&&y.push(U),(x==="tcpip-forward"||x==="cancel-tcpip-forward"||x==="no-more-sessions@openssh.com"||x==="streamlocal-forward@openssh.com"||x==="cancel-streamlocal-forward@openssh.com")&&Kt(this,"request")&&this.authenticated){let re,G;if(w){let Y=!1;re=te=>{if(Y)return;Y=!0;let ce;x==="tcpip-forward"&&I.bindPort===0&&typeof te=="number"&&(ce=Buffer.allocUnsafe(4),am(ce,te,0)),R("SUCCESS",ce)},G=()=>{Y||(Y=!0,R("FAILURE"))}}if(x==="no-more-sessions@openssh.com"){this.noMoreSessions=!0,re&&re();return}this.emit("request",re,G,x,I)}else w&&R("FAILURE")}}});t.pause(),rm.then(()=>{k.start(),t.on("data",O=>{try{k.parse(O,0,O.length)}catch(x){this.emit("error",x);try{Rs(t)&&t.end()}catch{}}}),t.resume()}).catch(O=>{this.emit("error",O);try{Rs(t)&&t.end()}catch{}}),t.on("error",O=>{O.level="socket",this.emit("error",O)}).once("end",()=>{i&&i("Socket ended"),k.cleanup(),this.emit("end")}).once("close",()=>{i&&i("Socket closed"),k.cleanup(),this.emit("close");let O=new Error("No response from server");this._chanMgr.cleanup(O)});let K=(O,x,w,I)=>{u===O&&!this.authenticated&&(x?(u=void 0,this.authenticated=!0,k.authSuccess(),l=[],this.emit("ready")):(k.authFailure(w,I),l.length&&(u=l.pop(),Kt(this,"authentication")?this.emit("authentication",u):u.reject())))};function ee(){for(;y.length>0&&y[0].type;){let O=y.shift();O.type==="SUCCESS"&&k.requestSuccess(O.buf),O.type==="FAILURE"&&k.requestFailure()}}}end(){return this._sock&&Rs(this._sock)&&(this._protocol.disconnect(Fr.BY_APPLICATION),this._sock.end()),this}x11(t,e,r){return Qa(this,"x11",{originAddr:t,originPort:e},r),this}forwardOut(t,e,r,s,i){return Qa(this,"forwarded-tcpip",{boundAddr:t,boundPort:e,remoteAddr:r,remotePort:s},i),this}openssh_forwardOutStreamLocal(t,e){return Qa(this,"forwarded-streamlocal@openssh.com",{socketPath:t},e),this}rekey(t){let e;try{this._protocol.rekey()}catch(r){e=r}typeof t=="function"&&(e?process.nextTick(t,e):this.once("rekey",t))}setNoDelay(t){return this._sock&&typeof this._sock.setNoDelay=="function"&&this._sock.setNoDelay(t),this}};function Qa(n,t,e,r){let s=Yn,i=zn;typeof e=="function"&&(r=e,e={});let o=(c,f)=>{r(c,f)};o.type=t;let a=n._chanMgr.add(o);if(a===-1){r(new Error("No free channels available"));return}switch(t){case"forwarded-tcpip":n._protocol.forwardedTcpip(a,s,i,e);break;case"x11":n._protocol.x11(a,s,i,e);break;case"forwarded-streamlocal@openssh.com":n._protocol.openssh_forwardedStreamLocal(a,s,i,e);break;default:throw new Error(`Unsupported channel type: ${t}`)}}function pm(n,t){return n-t}Ka.exports=sn;Ka.exports.IncomingClient=Ts});var Yl=at((PE,Gl)=>{"use strict";var{createCipheriv:gm,generateKeyPair:mm,generateKeyPairSync:Am,getCurves:Em,randomBytes:ql}=require("crypto"),{Ber:At}=ni(),_m=fo().pbkdf,{CIPHER_INFO:ym}=Qn(),bm=16,xm=16,Sm=Em(),wm=new Map(Object.entries(ym));function Kl(n,t){if(typeof n!="string")throw new TypeError("Key type must be a string");let e={type:"spki",format:"der"},r={type:"pkcs8",format:"der"};switch(n.toLowerCase()){case"rsa":{if(typeof t!="object"||t===null)throw new TypeError("Missing options object for RSA key");let s=t.bits;if(!Number.isInteger(s))throw new TypeError("RSA bits must be an integer");if(s<=0||s>16384)throw new RangeError("RSA bits must be non-zero and <= 16384");return["rsa",{modulusLength:s,publicKeyEncoding:e,privateKeyEncoding:r}]}case"ecdsa":{if(typeof t!="object"||t===null)throw new TypeError("Missing options object for ECDSA key");if(!Number.isInteger(t.bits))throw new TypeError("ECDSA bits must be an integer");let s;switch(t.bits){case 256:s="prime256v1";break;case 384:s="secp384r1";break;case 521:s="secp521r1";break;default:throw new Error("ECDSA bits must be 256, 384, or 521")}if(!Sm.includes(s))throw new Error("Unsupported ECDSA bits value");return["ec",{namedCurve:s,publicKeyEncoding:e,privateKeyEncoding:r}]}case"ed25519":return["ed25519",{publicKeyEncoding:e,privateKeyEncoding:r}];default:throw new Error(`Unsupported key type: ${n}`)}}function Im(n,t,e){switch(n){case"rsa":{let r=new At.Reader(e);if(r.readSequence(),r.readInt()!==0)throw new Error("Unsupported version in RSA private key");if(r.readSequence(),r.readOID()!=="1.2.840.113549.1.1.1")throw new Error("Bad RSA private OID");if(r.readByte()!==At.Null)throw new Error("Malformed RSA private key (expected null)");if(r.readByte()!==0)throw new Error("Malformed RSA private key (expected zero-length null)");if(r=new At.Reader(r.readString(At.OctetString,!0)),r.readSequence(),r.readInt()!==0)throw new Error("Unsupported version in RSA private key");let s=r.readString(At.Integer,!0),i=r.readString(At.Integer,!0),o=r.readString(At.Integer,!0),a=r.readString(At.Integer,!0),c=r.readString(At.Integer,!0);r.readString(At.Integer,!0),r.readString(At.Integer,!0);let f=r.readString(At.Integer,!0),l=Buffer.from("ssh-rsa"),u=Buffer.allocUnsafe(4+l.length+4+s.length+4+i.length+4+o.length+4+f.length+4+a.length+4+c.length),h=0;u.writeUInt32BE(l.length,h+=0),u.set(l,h+=4),u.writeUInt32BE(s.length,h+=l.length),u.set(s,h+=4),u.writeUInt32BE(i.length,h+=s.length),u.set(i,h+=4),u.writeUInt32BE(o.length,h+=i.length),u.set(o,h+=4),u.writeUInt32BE(f.length,h+=o.length),u.set(f,h+=4),u.writeUInt32BE(a.length,h+=f.length),u.set(a,h+=4),u.writeUInt32BE(c.length,h+=a.length),u.set(c,h+=4);let g=Buffer.allocUnsafe(4+l.length+4+i.length+4+s.length);return h=0,g.writeUInt32BE(l.length,h+=0),g.set(l,h+=4),g.writeUInt32BE(i.length,h+=l.length),g.set(i,h+=4),g.writeUInt32BE(s.length,h+=i.length),g.set(s,h+=4),{sshName:l.toString(),priv:u,pub:g}}case"ec":{let r=new At.Reader(t);if(r.readSequence(),r.readSequence(),r.readOID()!=="1.2.840.10045.2.1")throw new Error("Bad ECDSA public OID");r.readOID();let s=r.readString(At.BitString,!0);{let h=0;for(;h<s.length&&s[h]===0;++h);h>0&&(s=s.slice(h))}if(r=new At.Reader(e),r.readSequence(),r.readInt()!==0)throw new Error("Unsupported version in ECDSA private key");if(r.readSequence(),r.readOID()!=="1.2.840.10045.2.1")throw new Error("Bad ECDSA private OID");let i=r.readOID(),o;switch(i){case"1.2.840.10045.3.1.7":o="nistp256";break;case"1.3.132.0.34":o="nistp384";break;case"1.3.132.0.35":o="nistp521";break;default:throw new Error("Unsupported curve in ECDSA private key")}if(r=new At.Reader(r.readString(At.OctetString,!0)),r.readSequence(),r.readInt()!==1)throw new Error("Unsupported version in ECDSA private key");let a=Buffer.concat([Buffer.from([0]),r.readString(At.OctetString,!0)]),c=Buffer.from(`ecdsa-sha2-${o}`);o=Buffer.from(o);let f=Buffer.allocUnsafe(4+c.length+4+o.length+4+s.length+4+a.length),l=0;f.writeUInt32BE(c.length,l+=0),f.set(c,l+=4),f.writeUInt32BE(o.length,l+=c.length),f.set(o,l+=4),f.writeUInt32BE(s.length,l+=o.length),f.set(s,l+=4),f.writeUInt32BE(a.length,l+=s.length),f.set(a,l+=4);let u=Buffer.allocUnsafe(4+c.length+4+o.length+4+s.length);return l=0,u.writeUInt32BE(c.length,l+=0),u.set(c,l+=4),u.writeUInt32BE(o.length,l+=c.length),u.set(o,l+=4),u.writeUInt32BE(s.length,l+=o.length),u.set(s,l+=4),{sshName:c.toString(),priv:f,pub:u}}case"ed25519":{let r=new At.Reader(t);if(r.readSequence(),r.readSequence(),r.readOID()!=="1.3.101.112")throw new Error("Bad ED25519 public OID");let s=r.readString(At.BitString,!0);{let l=0;for(;l<s.length&&s[l]===0;++l);l>0&&(s=s.slice(l))}if(r=new At.Reader(e),r.readSequence(),r.readInt()!==0)throw new Error("Unsupported version in ED25519 private key");if(r.readSequence(),r.readOID()!=="1.3.101.112")throw new Error("Bad ED25519 private OID");r=new At.Reader(r.readString(At.OctetString,!0));let i=r.readString(At.OctetString,!0),o=Buffer.from("ssh-ed25519"),a=Buffer.allocUnsafe(4+o.length+4+s.length+4+(i.length+s.length)),c=0;a.writeUInt32BE(o.length,c+=0),a.set(o,c+=4),a.writeUInt32BE(s.length,c+=o.length),a.set(s,c+=4),a.writeUInt32BE(i.length+s.length,c+=s.length),a.set(i,c+=4),a.set(s,c+=i.length);let f=Buffer.allocUnsafe(4+o.length+4+s.length);return c=0,f.writeUInt32BE(o.length,c+=0),f.set(o,c+=4),f.writeUInt32BE(s.length,c+=o.length),f.set(s,c+=4),{sshName:o.toString(),priv:a,pub:f}}}}function Vl(n,t,e,r){let s="new",i,o="";if(typeof r=="object"&&r!==null&&(typeof r.comment=="string"&&r.comment&&(o=r.comment),typeof r.format=="string"&&r.format&&(s=r.format),r.passphrase)){let a;if(typeof r.passphrase=="string")a=Buffer.from(r.passphrase);else if(Buffer.isBuffer(r.passphrase))a=r.passphrase;else throw new Error("Invalid passphrase");if(r.cipher===void 0)throw new Error("Missing cipher name");let c=wm.get(r.cipher);if(c===void 0)throw new Error("Invalid cipher name");if(s==="new"){let f=xm;if(r.rounds!==void 0){if(!Number.isInteger(r.rounds))throw new TypeError("rounds must be an integer");r.rounds>0&&(f=r.rounds)}let l=Buffer.allocUnsafe(c.keyLen+c.ivLen),u=ql(bm);if(_m(a,a.length,u,u.length,l,l.length,f)!==0)return new Error("Failed to generate information to encrypt key");let g=Buffer.allocUnsafe(4+u.length+4);{let y=0;g.writeUInt32BE(u.length,y+=0),g.set(u,y+=4),g.writeUInt32BE(f,y+=u.length)}i={cipher:c,cipherName:r.cipher,kdfName:"bcrypt",kdfOptions:g,key:l.slice(0,c.keyLen),iv:l.slice(c.keyLen)}}}switch(s){case"new":{let a=`-----BEGIN OPENSSH PRIVATE KEY-----
|
|
15
|
+
`,c,f=Buffer.from(i?i.cipherName:"none"),l=Buffer.from(i?i.kdfName:"none"),u=i?i.kdfOptions:Buffer.alloc(0),h=i?i.cipher.blockLen:8,g=Im(n,t,e),y=ql(4),_=Buffer.from(o),b=8+g.priv.length+4+_.length,C=[];for(let ee=1;(b+C.length)%h;++ee)C.push(ee&255);C=Buffer.from(C);let L=Buffer.allocUnsafe(b+C.length),F;{let ee=0;L.set(y,ee+=0),L.set(y,ee+=4),L.set(g.priv,ee+=4),L.writeUInt32BE(_.length,ee+=g.priv.length),L.set(_,ee+=4),L.set(C,ee+=_.length)}if(i){let ee={authTagLength:i.cipher.authLen},O=gm(i.cipher.sslName,i.key,i.iv,ee);O.setAutoPadding(!1),L=Buffer.concat([O.update(L),O.final()]),i.cipher.authLen>0?F=O.getAuthTag():F=Buffer.alloc(0),i.key.fill(0),i.iv.fill(0)}else F=Buffer.alloc(0);let k=Buffer.from("openssh-key-v1\0"),K=Buffer.allocUnsafe(k.length+4+f.length+4+l.length+4+u.length+4+4+g.pub.length+4+L.length+F.length);{let ee=0;K.set(k,ee+=0),K.writeUInt32BE(f.length,ee+=k.length),K.set(f,ee+=4),K.writeUInt32BE(l.length,ee+=f.length),K.set(l,ee+=4),K.writeUInt32BE(u.length,ee+=l.length),K.set(u,ee+=4),K.writeUInt32BE(1,ee+=u.length),K.writeUInt32BE(g.pub.length,ee+=4),K.set(g.pub,ee+=4),K.writeUInt32BE(L.length,ee+=g.pub.length),K.set(L,ee+=4),K.set(F,ee+=L.length)}{let ee=K.base64Slice(0,K.length),O=ee.replace(/.{64}/g,`$&
|
|
16
16
|
`);ee.length&63&&(O+=`
|
|
17
17
|
`),a+=O}{let ee=g.pub.base64Slice(0,g.pub.length);c=`${g.sshName} ${ee}${o?` ${o}`:""}`}return a+=`-----END OPENSSH PRIVATE KEY-----
|
|
18
|
-
`,{private:a,public:c}}default:throw new Error("Invalid output key format")}}function
|
|
18
|
+
`,{private:a,public:c}}default:throw new Error("Invalid output key format")}}function Cm(){}Gl.exports={generateKeyPair:(n,t,e)=>{typeof t=="function"&&(e=t,t=void 0),typeof e!="function"&&(e=Cm);let r=Kl(n,t);mm(...r,(s,i,o)=>{if(s)return e(s);let a;try{a=Vl(r[0],i,o,t)}catch(c){return e(c)}e(null,a)})},generateKeyPairSync:(n,t)=>{let e=Kl(n,t),{publicKey:r,privateKey:s}=Am(...e);return Vl(e[0],r,s,t)}}});var Va=at((TE,zl)=>{"use strict";var{AgentProtocol:vm,BaseAgent:km,createAgent:Bm,CygwinAgent:Rm,OpenSSHAgent:Nm,PageantAgent:Pm}=Jo(),{SSHTTPAgent:Tm,SSHTTPSAgent:Lm}=Hl(),{parseKey:Um}=Kn(),{flagsToString:Dm,OPEN_MODE:Om,STATUS_CODE:Mm,stringToFlags:$m}=bi();zl.exports={AgentProtocol:vm,BaseAgent:km,createAgent:Bm,Client:$a(),CygwinAgent:Rm,HTTPAgent:Tm,HTTPSAgent:Lm,OpenSSHAgent:Nm,PageantAgent:Pm,Server:Wl(),utils:{parseKey:Um,...Yl(),sftp:{flagsToString:Dm,OPEN_MODE:Om,STATUS_CODE:Mm,stringToFlags:$m}}}});var Lh=require("node:events"),Uh=Vt(Va(),1);var Rh=require("node:events");var jl={name:"adduser",description:"Add a new user",category:"users",params:["<username> <password>"],run:async({authUser:n,shell:t,args:e})=>{if(n!=="root")return{stderr:"adduser: permission denied",exitCode:1};let[r,s]=e;return!r||!s?{stderr:"adduser: usage: adduser <username> <password>",exitCode:1}:(await t.users.addUser(r,s),{stdout:`adduser: user '${r}' created`,exitCode:0})}};function Xl(n){return Array.isArray(n)?n:[n]}function Ls(n,t){if(n===t)return{matched:!0,inlineValue:null};let e=`${t}=`;return n.startsWith(e)?{matched:!0,inlineValue:n.slice(e.length)}:{matched:!1,inlineValue:null}}function Fm(n,t={}){let e=new Set(t.flags??[]),r=new Set(t.flagsWithValue??[]),s=[],i=!1;for(let o=0;o<n.length;o+=1){let a=n[o];if(i){s.push(a);continue}if(a==="--"){i=!0;continue}let c=!1;for(let f of e){let{matched:l}=Ls(a,f);if(l){c=!0;break}}if(!c){for(let f of r){let l=Ls(a,f);if(l.matched){c=!0,l.inlineValue===null&&o+1<n.length&&(o+=1);break}}c||s.push(a)}}return s}function ne(n,t){let e=Xl(t);for(let r of n)for(let s of e)if(Ls(r,s).matched)return!0;return!1}function en(n,t){let e=Xl(t);for(let r=0;r<n.length;r+=1){let s=n[r];for(let i of e){let o=Ls(s,i);if(!o.matched)continue;if(o.inlineValue!==null)return o.inlineValue;let a=n[r+1];return a!==void 0&&a!=="--"?a:!0}}}function mn(n,t,e={}){return Fm(n,e)[t]}function zt(n,t={}){let e=new Set,r=new Map,s=[],i=new Set(t.flags??[]),o=new Set(t.flagsWithValue??[]),a=!1;for(let c=0;c<n.length;c+=1){let f=n[c];if(a){s.push(f);continue}if(f==="--"){a=!0;continue}if(i.has(f)){e.add(f);continue}if(o.has(f)){let u=n[c+1];u&&!u.startsWith("-")?(r.set(f,u),c+=1):r.set(f,"");continue}let l=Array.from(o).find(u=>f.startsWith(`${u}=`));if(l){r.set(l,f.slice(l.length+1));continue}s.push(f)}return{flags:e,flagsWithValues:r,positionals:s}}var Jl={name:"alias",description:"Define or display aliases",category:"shell",params:["[name[=value] ...]"],run:({args:n,env:t})=>{if(!t)return{exitCode:0};if(n.length===0)return{stdout:Object.entries(t.vars).filter(([s])=>s.startsWith("__alias_")).map(([s,i])=>`alias ${s.slice(8)}='${i}'`).join(`
|
|
19
19
|
`)||"",exitCode:0};let e=[];for(let r of n){let s=r.indexOf("=");if(s===-1){let i=t.vars[`__alias_${r}`];if(i)e.push(`alias ${r}='${i}'`);else return{stderr:`alias: ${r}: not found`,exitCode:1}}else{let i=r.slice(0,s),o=r.slice(s+1).replace(/^['"]|['"]$/g,"");t.vars[`__alias_${i}`]=o}}return{stdout:e.join(`
|
|
20
|
-
`)||void 0,exitCode:0}}},
|
|
20
|
+
`)||void 0,exitCode:0}}},Zl={name:"unalias",description:"Remove alias definitions",category:"shell",params:["<name...> | -a"],run:({args:n,env:t})=>{if(!t)return{exitCode:0};if(ne(n,["-a"])){for(let e of Object.keys(t.vars))e.startsWith("__alias_")&&delete t.vars[e];return{exitCode:0}}for(let e of n)delete t.vars[`__alias_${e}`];return{exitCode:0}}};var xn=Vt(require("node:path"),1),Hm=["/virtual-env-js/.auth"];function le(n,t){return!t||t.trim()===""?n:t.startsWith("/")?xn.posix.normalize(t):xn.posix.normalize(xn.posix.join(n,t))}function Qm(n){let t=n.startsWith("/")?xn.posix.normalize(n):xn.posix.normalize(`/${n}`);return Hm.some(e=>t===e||t.startsWith(`${e}/`))}function $e(n,t,e){if(n!=="root"&&Qm(t))throw new Error(`${e}: permission denied: ${t}`)}function eu(n){let e=(n.split("?")[0]?.split("#")[0]??n).split("/").filter(Boolean).pop();return e&&e.length>0?e:"index.html"}function Wm(n,t){let e=Array.from({length:n.length+1},()=>Array(t.length+1).fill(0));for(let r=0;r<=n.length;r+=1)e[r][0]=r;for(let r=0;r<=t.length;r+=1)e[0][r]=r;for(let r=1;r<=n.length;r+=1)for(let s=1;s<=t.length;s+=1){let i=n[r-1]===t[s-1]?0:1;e[r][s]=Math.min(e[r-1][s]+1,e[r][s-1]+1,e[r-1][s-1]+i)}return e[n.length][t.length]}function tu(n,t,e){let r=le(t,e);if(n.exists(r))return r;let s=xn.posix.dirname(r),i=xn.posix.basename(r),o=n.list(s),a=o.filter(f=>f.toLowerCase()===i.toLowerCase());if(a.length===1)return xn.posix.join(s,a[0]);let c=o.filter(f=>Wm(f.toLowerCase(),i.toLowerCase())<=1);return c.length===1?xn.posix.join(s,c[0]):r}function nu(n,t,e){return t.map(r=>{let s=le(n,r);return e(s).type==="directory"?`${r}/`:r}).join(" ")}function Qr(n){return n.packageManager}var ru={name:"apt",aliases:["apt-get"],description:"Package manager",category:"package",params:["<install|remove|update|upgrade|search|show|list> [pkg...]"],run:({args:n,shell:t,authUser:e})=>{let r=Qr(t);if(!r)return{stderr:"apt: package manager not initialised",exitCode:1};let s=n[0]?.toLowerCase(),i=n.slice(1),o=ne(i,["-q","--quiet","-qq"]),a=ne(i,["--purge"]),c=i.filter(l=>!l.startsWith("-"));if(["install","remove","purge","upgrade","update"].includes(s??"")&&e!=="root")return{stderr:`E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
|
|
21
21
|
E: Unable to acquire the dpkg frontend lock, are you root?`,exitCode:100};switch(s){case"install":{if(c.length===0)return{stderr:"apt: no packages specified",exitCode:1};let{output:l,exitCode:u}=r.install(c,{quiet:o});return{stdout:l||void 0,exitCode:u}}case"remove":case"purge":{if(c.length===0)return{stderr:"apt: no packages specified",exitCode:1};let{output:l,exitCode:u}=r.remove(c,{purge:s==="purge"||a,quiet:o});return{stdout:l||void 0,exitCode:u}}case"update":return{stdout:["Hit:1 fortune://packages.fortune.local aurora InRelease","Hit:2 fortune://security.fortune.local aurora-security InRelease","Reading package lists... Done","Building dependency tree... Done","Reading state information... Done","All packages are up to date."].join(`
|
|
22
22
|
`),exitCode:0};case"upgrade":return{stdout:["Reading package lists... Done","Building dependency tree... Done","Reading state information... Done","Calculating upgrade... Done","0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded."].join(`
|
|
23
23
|
`),exitCode:0};case"search":{let l=c[0];if(!l)return{stderr:"apt: search requires a term",exitCode:1};let u=r.search(l);return u.length===0?{stdout:`Sorting... Done
|
|
@@ -32,52 +32,52 @@ ${g.map(_=>`${_.name}/${_.section} ${_.version} ${_.architecture} [installed]`).
|
|
|
32
32
|
`)}`,exitCode:0}}return{stdout:`Listing... Done
|
|
33
33
|
${r.listAvailable().map(g=>`${g.name}/${g.section??"misc"} ${g.version} amd64`).join(`
|
|
34
34
|
`)}`,exitCode:0}}default:return{stdout:["Usage: apt [options] command","","Commands:"," install <pkg...> Install packages"," remove <pkg...> Remove packages"," purge <pkg...> Remove packages and config files"," update Refresh package index"," upgrade Upgrade all packages"," search <term> Search in package descriptions"," show <pkg> Show package details"," list [--installed] List packages"].join(`
|
|
35
|
-
`),exitCode:0}}}},
|
|
35
|
+
`),exitCode:0}}}},iu={name:"apt-cache",description:"Query the package cache",category:"package",params:["<search|show|policy> [pkg]"],run:({args:n,shell:t})=>{let e=Qr(t);if(!e)return{stderr:"apt-cache: package manager not initialised",exitCode:1};let r=n[0]?.toLowerCase(),s=n[1];switch(r){case"search":return s?{stdout:e.search(s).map(o=>`${o.name} - ${o.shortDesc??o.description}`).join(`
|
|
36
36
|
`)||"(no results)",exitCode:0}:{stderr:"Need a search term",exitCode:1};case"show":{if(!s)return{stderr:"Need a package name",exitCode:1};let i=e.show(s);return i?{stdout:i,exitCode:0}:{stderr:`N: Unable to locate package ${s}`,exitCode:100}}case"policy":{if(!s)return{stderr:"Need a package name",exitCode:1};let i=e.findInRegistry(s);if(!i)return{stderr:`N: Unable to locate package ${s}`,exitCode:100};let o=e.isInstalled(s);return{stdout:[`${s}:`,` Installed: ${o?i.version:"(none)"}`,` Candidate: ${i.version}`," Version table:",` ${i.version} 500`," 500 fortune://packages.fortune.local aurora/main amd64 Packages"].join(`
|
|
37
|
-
`),exitCode:0}}default:return{stderr:`apt-cache: unknown command '${r??""}'`,exitCode:1}}}};var
|
|
37
|
+
`),exitCode:0}}default:return{stderr:`apt-cache: unknown command '${r??""}'`,exitCode:1}}}};var su={name:"awk",description:"Pattern scanning and processing language (minimal)",category:"text",params:["[-F <sep>] '<program>' [file]"],run:({args:n,stdin:t})=>{let e=en(n,["-F"])??" ",r=n.find(c=>!c.startsWith("-")&&c!==e);if(!r)return{stderr:"awk: no program",exitCode:1};let s=r.match(/^\{?\s*print\s+([^}]+)\s*\}?$/);if(!s)return{stderr:`awk: unsupported program: ${r}`,exitCode:1};let i=s[1].split(/\s*,\s*/).map(c=>c.trim());return{stdout:(t??"").split(`
|
|
38
38
|
`).filter(Boolean).map(c=>{let f=c.split(e===" "?/\s+/:e);return i.map(l=>{if(l==="$0")return c;let u=parseInt(l.replace("$",""),10);return Number.isNaN(u)?l.replace(/"/g,""):f[u-1]??""}).join(e===" "?" ":e)}).join(`
|
|
39
|
-
`),exitCode:0}}};var
|
|
39
|
+
`),exitCode:0}}};var ou={name:"base64",description:"Encode/decode base64",category:"text",params:["[-d] [file]"],run:({args:n,stdin:t})=>{let e=ne(n,["-d","--decode"]),r=t??"";if(e)try{return{stdout:Buffer.from(r.trim(),"base64").toString("utf8"),exitCode:0}}catch{return{stderr:"base64: invalid input",exitCode:1}}return{stdout:Buffer.from(r).toString("base64"),exitCode:0}}};var au={name:"cat",description:"Concatenate and print files",category:"files",params:["[-n] [-b] <file...>"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:s})=>{let i=ne(r,["-n","--number"]),o=ne(r,["-b","--number-nonblank"]),a=r.filter(h=>!h.startsWith("-"));if(a.length===0&&s!==void 0)return{stdout:s,exitCode:0};if(a.length===0)return{stderr:"cat: missing file operand",exitCode:1};let c=[];for(let h of a){let g=tu(t.vfs,e,h);$e(n,g,"cat"),c.push(t.vfs.readFile(g))}let f=c.join("");if(!i&&!o)return{stdout:f,exitCode:0};let l=1;return{stdout:f.split(`
|
|
40
40
|
`).map(h=>o&&h.trim()===""?h:`${String(l++).padStart(6)} ${h}`).join(`
|
|
41
|
-
`),exitCode:0}}};var
|
|
41
|
+
`),exitCode:0}}};var cu={name:"cd",description:"Change directory",category:"navigation",params:["[path]"],run:({authUser:n,shell:t,cwd:e,args:r,mode:s})=>{let i=le(e,r[0]??"/virtual-env-js");return $e(n,i,"cd"),t.vfs.stat(i).type!=="directory"?{stderr:`cd: not a directory: ${i}`,exitCode:1}:s==="exec"?{exitCode:0}:{nextCwd:i,exitCode:0}}};function qm(n,t){let e=/^([ugoa]*)([+\-=])([rwx]*)$/,r=t.split(","),s=n;for(let i of r){let o=i.trim().match(e);if(!o)return null;let[,a="a",c,f=""]=o,l=a===""||a==="a"?["u","g","o"]:a.split(""),u={u:{r:256,w:128,x:64},g:{r:32,w:16,x:8},o:{r:4,w:2,x:1}};for(let h of l)for(let g of f.split("")){let y=u[h]?.[g];if(y!==void 0){if(c==="+")s|=y;else if(c==="-")s&=~y;else if(c==="="){let _=Object.values(u[h]??{}).reduce((b,C)=>b|C,0);s=s&~_|y}}}}return s}var fu={name:"chmod",description:"Change file permissions",category:"files",params:["<mode> <file>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let[s,i]=r;if(!s||!i)return{stderr:"chmod: missing operand",exitCode:1};let o=le(e,i);try{if($e(n,o,"chmod"),!t.vfs.exists(o))return{stderr:`chmod: ${i}: No such file or directory`,exitCode:1};let a,c=parseInt(s,8);if(!Number.isNaN(c)&&/^[0-7]+$/.test(s))a=c;else{let f=t.vfs.stat(o).mode,l=qm(f,s);if(l===null)return{stderr:`chmod: invalid mode: ${s}`,exitCode:1};a=l}return t.vfs.chmod(o,a),{exitCode:0}}catch(a){return{stderr:`chmod: ${a instanceof Error?a.message:String(a)}`,exitCode:1}}}};var lu={name:"clear",description:"Clear the terminal screen",category:"shell",params:[],run:()=>({clearScreen:!0,stdout:"",exitCode:0})};var uu={name:"cp",description:"Copy files or directories",category:"files",params:["[-r] <source> <dest>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=ne(r,["-r","-R","--recursive"]),i=r.filter(l=>!l.startsWith("-")),[o,a]=i;if(!o||!a)return{stderr:"cp: missing operand",exitCode:1};let c=le(e,o),f=le(e,a);try{if($e(n,c,"cp"),$e(n,f,"cp"),!t.vfs.exists(c))return{stderr:`cp: ${o}: No such file or directory`,exitCode:1};if(t.vfs.stat(c).type==="directory"){if(!s)return{stderr:`cp: ${o}: is a directory (use -r)`,exitCode:1};let u=(g,y)=>{t.vfs.mkdir(y,493);for(let _ of t.vfs.list(g)){let b=`${g}/${_}`,C=`${y}/${_}`;if(t.vfs.stat(b).type==="directory")u(b,C);else{let F=t.vfs.readFileRaw(b);t.writeFileAsUser(n,C,F)}}},h=t.vfs.exists(f)&&t.vfs.stat(f).type==="directory"?`${f}/${o.split("/").pop()}`:f;u(c,h)}else{let u=t.vfs.exists(f)&&t.vfs.stat(f).type==="directory"?`${f}/${o.split("/").pop()}`:f,h=t.vfs.readFileRaw(c);t.writeFileAsUser(n,u,h)}return{exitCode:0}}catch(l){return{stderr:`cp: ${l instanceof Error?l.message:String(l)}`,exitCode:1}}}};var du={name:"curl",description:"Transfer data from or to a server (pure fetch)",category:"network",params:["[options] <url>"],run:async({authUser:n,cwd:t,args:e,shell:r})=>{let{flagsWithValues:s,positionals:i}=zt(e,{flagsWithValue:["-o","--output","-X","--request","-d","--data","-H","--header","-u","--user"]});if(ne(e,["--help","-h"]))return{stdout:["Usage: curl [options] <url>"," -o, --output <file> Write to file"," -X, --request <method> HTTP method"," -d, --data <data> POST data"," -H, --header <hdr> Extra header"," -s, --silent Silent mode"," -I, --head Fetch headers only"," -L, --location Follow redirects"," -v, --verbose Verbose"].join(`
|
|
42
42
|
`),exitCode:0};let o=i[0];if(!o)return{stderr:"curl: no URL specified",exitCode:1};let a=s.get("-o")??s.get("--output")??null,c=(s.get("-X")??s.get("--request")??"GET").toUpperCase(),f=s.get("-d")??s.get("--data")??null,l=s.get("-H")??s.get("--header")??null,u=ne(e,["-s","--silent"]),h=ne(e,["-I","--head"]),g=ne(e,["-L","--location"]),y=ne(e,["-v","--verbose"]),_={"User-Agent":"curl/7.88.1"};if(l){let K=l.indexOf(":");K!==-1&&(_[l.slice(0,K).trim()]=l.slice(K+1).trim())}let b=f&&c==="GET"?"POST":c,C={method:b,headers:_,redirect:g?"follow":"manual"};f&&(_["Content-Type"]??="application/x-www-form-urlencoded",C.body=f);let L=[];y&&(L.push(`* Trying ${o}...`,"* Connected"),L.push(`> ${b} / HTTP/1.1`,`> Host: ${new URL(o).host}`));let F;try{F=await fetch(o,C)}catch(K){return{stderr:`curl: (6) Could not resolve host: ${K instanceof Error?K.message:String(K)}`,exitCode:6}}if(y&&L.push(`< HTTP/1.1 ${F.status} ${F.statusText}`),h){let K=[`HTTP/1.1 ${F.status} ${F.statusText}`];for(let[ee,O]of F.headers.entries())K.push(`${ee}: ${O}`);return{stdout:`${K.join(`\r
|
|
43
43
|
`)}\r
|
|
44
44
|
`,exitCode:0}}let k;try{k=await F.text()}catch{return{stderr:"curl: failed to read response body",exitCode:1}}if(a){let K=le(t,a);return $e(n,K,"curl"),r.writeFileAsUser(n,K,k),u||L.push(` % Total % Received
|
|
45
45
|
100 ${k.length} 100 ${k.length}`),{stderr:L.join(`
|
|
46
46
|
`)||void 0,exitCode:F.ok?0:22}}return{stdout:k,stderr:L.length>0?L.join(`
|
|
47
|
-
`):void 0,exitCode:F.ok?0:22}}};var
|
|
47
|
+
`):void 0,exitCode:F.ok?0:22}}};var hu={name:"cut",description:"Remove sections from lines",category:"text",params:["-d <delim> -f <fields> [file]"],run:({args:n,stdin:t})=>{let e=en(n,["-d"])??" ",s=(en(n,["-f"])??"1").split(",").map(a=>{let[c,f]=a.split("-").map(Number);return f!==void 0?{from:(c??1)-1,to:f-1}:{from:(c??1)-1,to:(c??1)-1}});return{stdout:(t??"").split(`
|
|
48
48
|
`).map(a=>{let c=a.split(e),f=[];for(let l of s)for(let u=l.from;u<=Math.min(l.to,c.length-1);u++)f.push(c[u]??"");return f.join(e)}).join(`
|
|
49
|
-
`),exitCode:0}}};var
|
|
50
|
-
`),exitCode:0};let o=n.filter(a=>!a.startsWith("-"));for(let a of o){let c=a.indexOf("=");if(c===-1)a in t.vars||(t.vars[a]="");else{let f=a.slice(0,c),l=a.slice(c+1);if(e){let u=parseInt(l,10);l=Number.isNaN(u)?"0":String(u)}t.vars[f]=l}}return{exitCode:0}}};var
|
|
51
|
-
${a}`,exitCode:0}}};var
|
|
49
|
+
`),exitCode:0}}};var pu={name:"date",description:"Print current date and time",category:"system",params:["[+format]"],run:({args:n})=>{let t=new Date,e=n[0];return e?.startsWith("+")?{stdout:e.slice(1).replace("%Y",String(t.getFullYear())).replace("%m",String(t.getMonth()+1).padStart(2,"0")).replace("%d",String(t.getDate()).padStart(2,"0")).replace("%H",String(t.getHours()).padStart(2,"0")).replace("%M",String(t.getMinutes()).padStart(2,"0")).replace("%S",String(t.getSeconds()).padStart(2,"0")).replace("%s",String(Math.floor(t.getTime()/1e3))),exitCode:0}:{stdout:t.toString(),exitCode:0}}};var gu={name:"declare",aliases:["local","typeset"],description:"Declare variables and give them attributes",category:"shell",params:["[-i] [-r] [-x] [-a] [name[=value]...]"],run:({args:n,env:t})=>{if(!t)return{exitCode:0};let e=ne(n,["-i"]),r=ne(n,["-r"]),s=ne(n,["-x"]);if(n.filter(a=>!a.startsWith("-")).length===0)return{stdout:Object.entries(t.vars).map(([c,f])=>`declare -- ${c}="${f}"`).join(`
|
|
50
|
+
`),exitCode:0};let o=n.filter(a=>!a.startsWith("-"));for(let a of o){let c=a.indexOf("=");if(c===-1)a in t.vars||(t.vars[a]="");else{let f=a.slice(0,c),l=a.slice(c+1);if(e){let u=parseInt(l,10);l=Number.isNaN(u)?"0":String(u)}t.vars[f]=l}}return{exitCode:0}}};var mu={name:"deluser",description:"Delete a user",category:"users",params:["<username>"],run:async({authUser:n,args:t,shell:e})=>{if(n!=="root")return{stderr:"deluser: permission denied",exitCode:1};let[r]=t;return r?(await e.users.deleteUser(r),{stdout:`deluser: user '${r}' deleted`,exitCode:0}):{stderr:"deluser: usage: deluser <username>",exitCode:1}}};var Au={name:"df",description:"Report filesystem disk space usage",category:"system",params:["[-h]"],run:({shell:n})=>{let e=(n.vfs.getUsageBytes()/1024).toFixed(0),r="1048576",s=String(Number(r)-Number(e)),i=Math.round(Number(e)/Number(r)*100),o="Filesystem 1K-blocks Used Available Use% Mounted on",a=`virtual-fs ${r.padStart(9)} ${e.padStart(7)} ${s.padStart(9)} ${i}% /`;return{stdout:`${o}
|
|
51
|
+
${a}`,exitCode:0}}};var Eu={name:"diff",description:"Compare files line by line",category:"text",params:["<file1> <file2>"],run:({shell:n,cwd:t,args:e})=>{let[r,s]=e;if(!r||!s)return{stderr:"diff: missing operand",exitCode:1};let i=le(t,r),o=le(t,s),a,c;try{a=n.vfs.readFile(i).split(`
|
|
52
52
|
`)}catch{return{stderr:`diff: ${r}: No such file or directory`,exitCode:2}}try{c=n.vfs.readFile(o).split(`
|
|
53
53
|
`)}catch{return{stderr:`diff: ${s}: No such file or directory`,exitCode:2}}let f=[],l=Math.max(a.length,c.length);for(let u=0;u<l;u++){let h=a[u],g=c[u];h!==g&&(h!==void 0&&f.push(`< ${h}`),g!==void 0&&f.push(`> ${g}`))}return{stdout:f.join(`
|
|
54
|
-
`),exitCode:f.length>0?1:0}}};var
|
|
54
|
+
`),exitCode:f.length>0?1:0}}};var _u={name:"dpkg",description:"Debian package manager low-level tool",category:"package",params:["[-l] [-s pkg] [-L pkg] [-i pkg] [--remove pkg]"],run:({args:n,authUser:t,shell:e})=>{let r=Qr(e);if(!r)return{stderr:"dpkg: package manager not initialised",exitCode:1};let s=ne(n,["-l","--list"]),i=ne(n,["-s","--status"]),o=ne(n,["-L","--listfiles"]),a=ne(n,["-r","--remove"]),c=ne(n,["-P","--purge"]),{positionals:f}=zt(n,{flags:["-l","--list","-s","--status","-L","--listfiles","-r","--remove","-P","--purge"]});if(s){let l=r.listInstalled();if(l.length===0)return{stdout:["Desired=Unknown/Install/Remove/Purge/Hold","|Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend","|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)","||/ Name Version Architecture Description","+++-==============-===============-============-========================================","(no packages installed)"].join(`
|
|
55
55
|
`),exitCode:0};let u=["Desired=Unknown/Install/Remove/Purge/Hold","|Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend","|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)","||/ Name Version Architecture Description","+++-==============-===============-============-========================================"],h=l.map(g=>{let y=g.name.padEnd(14).slice(0,14),_=g.version.padEnd(15).slice(0,15),b=g.architecture.padEnd(12).slice(0,12),C=(g.description||"").slice(0,40);return`ii ${y} ${_} ${b} ${C}`});return{stdout:[...u,...h].join(`
|
|
56
56
|
`),exitCode:0}}if(i){let l=f[0];if(!l)return{stderr:"dpkg: -s needs a package name",exitCode:1};let u=r.show(l);return u?{stdout:u,exitCode:0}:{stderr:`dpkg-query: package '${l}' is not installed and no information is available`,exitCode:1}}if(o){let l=f[0];if(!l)return{stderr:"dpkg: -L needs a package name",exitCode:1};let u=r.listInstalled().find(h=>h.name===l);return u?u.files.length===0?{stdout:"/.keep",exitCode:0}:{stdout:u.files.join(`
|
|
57
57
|
`),exitCode:0}:{stderr:`dpkg-query: package '${l}' is not installed`,exitCode:1}}if(a||c){if(t!=="root")return{stderr:"dpkg: error: requested operation requires superuser privilege",exitCode:2};if(f.length===0)return{stderr:"dpkg: error: need an action option",exitCode:2};let{output:l,exitCode:u}=r.remove(f,{purge:c});return{stdout:l||void 0,exitCode:u}}return{stdout:["Usage: dpkg [<option>...] <command>","","Commands:"," -l, --list List packages matching given pattern"," -s, --status <pkg>... Report status of specified package"," -L, --listfiles <pkg>... List files owned by package"," -r, --remove <pkg>... Remove <pkg> but leave its configuration"," -P, --purge <pkg>... Remove <pkg> and its configuration"].join(`
|
|
58
|
-
`),exitCode:0}}},
|
|
58
|
+
`),exitCode:0}}},yu={name:"dpkg-query",description:"Show information about installed packages",category:"package",params:["-W [pkg] | -l [pattern]"],run:({args:n,shell:t})=>{let e=Qr(t);if(!e)return{stderr:"dpkg-query: package manager not initialised",exitCode:1};let r=ne(n,["-l"]),s=ne(n,["-W","--show"]),{positionals:i}=zt(n,{flags:["-l","-W","--show"]});if(r||s){let o=e.listInstalled(),a=i[0],c=a?o.filter(l=>l.name.includes(a)):o;return s?{stdout:c.map(l=>`${l.name} ${l.version}`).join(`
|
|
59
59
|
`),exitCode:0}:{stdout:c.map(l=>{let u=l.name.padEnd(14).slice(0,14),h=l.version.padEnd(15).slice(0,15);return`ii ${u} ${h} amd64 ${(l.description||"").slice(0,40)}`}).join(`
|
|
60
|
-
`)||"(no packages match)",exitCode:0}}return{stderr:"dpkg-query: need a flag (-l, -W)",exitCode:1}}};var
|
|
61
|
-
`),exitCode:0}}};function
|
|
62
|
-
`).replace(/\\t/g," ").replace(/\\r/g,"\r").replace(/\\\\/g,"\\").replace(/\\a/g,"\x07").replace(/\\b/g,"\b").replace(/\\f/g,"\f").replace(/\\v/g,"\v").replace(/\\0(\d{1,3})/g,(t,e)=>String.fromCharCode(parseInt(e,8)))}var
|
|
63
|
-
`,exitCode:0}}};var
|
|
64
|
-
`),exitCode:0}}};var
|
|
65
|
-
`),exitCode:0};for(let e of n)if(e.includes("=")){let r=e.indexOf("="),s=e.slice(0,r),i=e.slice(r+1);t.vars[s]=i}return{exitCode:0}}};var
|
|
66
|
-
`),exitCode:0}}};var
|
|
67
|
-
`),exitCode:0}}};var
|
|
60
|
+
`)||"(no packages match)",exitCode:0}}return{stderr:"dpkg-query: need a flag (-l, -W)",exitCode:1}}};var bu={name:"du",description:"Estimate file space usage",category:"system",params:["[-h] [-s] [path]"],run:({shell:n,cwd:t,args:e})=>{let r=ne(e,["-h"]),s=ne(e,["-s"]),i=e.find(l=>!l.startsWith("-"))??".",o=le(t,i),a=l=>r?`${(l/1024).toFixed(1)}K`:String(Math.ceil(l/1024));if(!n.vfs.exists(o))return{stderr:`du: ${i}: No such file or directory`,exitCode:1};if(s||n.vfs.stat(o).type==="file")return{stdout:`${a(n.vfs.getUsageBytes(o))} ${i}`,exitCode:0};let c=[],f=(l,u)=>{let h=0;for(let g of n.vfs.list(l)){let y=`${l}/${g}`,_=`${u}/${g}`,b=n.vfs.stat(y);b.type==="directory"?h+=f(y,_):(h+=b.size,s||c.push(`${a(b.size)} ${_}`))}return c.push(`${a(h)} ${u}`),h};return f(o,i),{stdout:c.join(`
|
|
61
|
+
`),exitCode:0}}};function Km(n,t){let e=n.replace(/\b([A-Za-z_][A-Za-z0-9_]*)\b/g,(r,s)=>{let i=t[s];return i!==void 0&&i!==""?i:"0"});if(!/^[\d\s+\-*/%()^!&|<>=,. ]+$/.test(e))return NaN;try{let r=Function(`"use strict"; return (${e.replace(/\*\*/g,"**")});`)();return typeof r=="number"?Math.trunc(r):NaN}catch{return NaN}}function Vm(n,t){let e=[],r=0;for(;r<n.length;){let s=n.indexOf("'",r);if(s===-1){e.push(t(n.slice(r)));break}e.push(t(n.slice(r,s)));let i=n.indexOf("'",s+1);if(i===-1){e.push(n.slice(s));break}e.push(n.slice(s,i+1)),r=i+1}return e.join("")}function Ga(n,t,e=0,r){let s=r??t.HOME??"/home/user";return Vm(n,i=>{let o=i;return o=o.replace(/(^|[\s:])~(\/|$)/g,(a,c,f)=>`${c}${s}${f}`),o=o.replace(/\$\?/g,String(e)),o=o.replace(/\$\$/g,"1"),o=o.replace(/\$#/g,"0"),o=o.replace(/\$\(\(([^)]+(?:\([^)]*\)[^)]*)*)\)\)/g,(a,c)=>{let f=Km(c,t);return Number.isNaN(f)?"0":String(f)}),o=o.replace(/\$\{#([A-Za-z_][A-Za-z0-9_]*)\}/g,(a,c)=>String((t[c]??"").length)),o=o.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*):-([^}]*)\}/g,(a,c,f)=>t[c]!==void 0&&t[c]!==""?t[c]:f),o=o.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*):=([^}]*)\}/g,(a,c,f)=>((t[c]===void 0||t[c]==="")&&(t[c]=f),t[c])),o=o.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*):\+([^}]*)\}/g,(a,c,f)=>t[c]!==void 0&&t[c]!==""?f:""),o=o.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g,(a,c)=>t[c]??""),o=o.replace(/\$([A-Za-z_][A-Za-z0-9_]*)/g,(a,c)=>t[c]??""),o})}async function Us(n,t,e,r){if(n.includes("$(")){let s="",i=!1,o=0;for(;o<n.length;){let a=n[o];if(a==="'"&&!i){i=!0,s+=a,o++;continue}if(a==="'"&&i){i=!1,s+=a,o++;continue}if(!i&&a==="$"&&n[o+1]==="("){if(n[o+2]==="("){s+=a,o++;continue}let c=0,f=o+1;for(;f<n.length;){if(n[f]==="(")c++;else if(n[f]===")"&&(c--,c===0))break;f++}let l=n.slice(o+2,f).trim(),u=(await r(l)).replace(/\n$/,"");s+=u,o=f+1;continue}s+=a,o++}n=s}return Ga(n,t,e)}function Gm(n){return n.replace(/\\n/g,`
|
|
62
|
+
`).replace(/\\t/g," ").replace(/\\r/g,"\r").replace(/\\\\/g,"\\").replace(/\\a/g,"\x07").replace(/\\b/g,"\b").replace(/\\f/g,"\f").replace(/\\v/g,"\v").replace(/\\0(\d{1,3})/g,(t,e)=>String.fromCharCode(parseInt(e,8)))}var xu={name:"echo",description:"Display text",category:"shell",params:["[-n] [-e] [text...]"],run:({args:n,stdin:t,env:e})=>{let{flags:r,positionals:s}=zt(n,{flags:["-n","-e","-E"]}),i=r.has("-n"),o=r.has("-e"),a=s.length>0?s.join(" "):t??"",c=Ga(a,e?.vars??{},e?.lastExitCode??0),f=o?Gm(c):c;return{stdout:i?f:`${f}
|
|
63
|
+
`,exitCode:0}}};var Su={name:"env",description:"Print environment variables",category:"shell",params:[],run:({env:n,authUser:t})=>{let e={...n.vars,USER:t,HOME:`/home/${t}`};return{stdout:Object.entries(e).map(([r,s])=>`${r}=${s}`).join(`
|
|
64
|
+
`),exitCode:0}}};var wu={name:"exit",aliases:["bye"],description:"Exit the shell session",category:"shell",params:["[code]"],run:({args:n})=>({closeSession:!0,exitCode:parseInt(n[0]??"0",10)||0})};var Iu={name:"export",description:"Set shell environment variable",category:"shell",params:["[VAR=value]"],run:({args:n,env:t})=>{if(n.length===0)return{stdout:Object.entries(t.vars).map(([r,s])=>`declare -x ${r}="${s}"`).join(`
|
|
65
|
+
`),exitCode:0};for(let e of n)if(e.includes("=")){let r=e.indexOf("="),s=e.slice(0,r),i=e.slice(r+1);t.vars[s]=i}return{exitCode:0}}};var Cu={name:"find",description:"Search for files",category:"files",params:["[path] [-name <pattern>] [-type f|d]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=en(r,["-name"]),i=en(r,["-type"]),a=r.filter(h=>!h.startsWith("-")&&h!==s&&h!==i)[0]??".",c=le(e,a);try{if($e(n,c,"find"),!t.vfs.exists(c))return{stderr:`find: ${a}: No such file or directory`,exitCode:1}}catch(h){return{stderr:`find: ${h instanceof Error?h.message:String(h)}`,exitCode:1}}let f=s?new RegExp(`^${s.replace(/\./g,"\\.").replace(/\*/g,".*").replace(/\?/g,".")}$`):null,l=[],u=(h,g)=>{let y=t.vfs.stat(h),_=!i||i==="f"&&y.type==="file"||i==="d"&&y.type==="directory",b=!f||f.test(h.split("/").pop()??"");if(_&&b&&l.push(g),y.type==="directory")for(let C of t.vfs.list(h)){let L=`${h}/${C}`,F=`${g}/${C}`;u(L,F)}};return u(c,a),{stdout:l.join(`
|
|
66
|
+
`),exitCode:0}}};var Ds=Vt(require("node:os"),1);var vu={name:"free",description:"Display amount of free and used memory",category:"system",params:["[-h] [-m] [-g]"],run:({args:n})=>{let t=ne(n,["-h","--human"]),e=ne(n,["-m"]),r=ne(n,["-g"]),s=Ds.totalmem(),i=Ds.freemem(),o=s-i,a=Math.floor(s*.02),c=Math.floor(s*.05),f=Math.floor(i*.95),l=Math.floor(s*.5),u=_=>t?_>=1024*1024*1024?`${(_/(1024*1024*1024)).toFixed(1)}G`:_>=1024*1024?`${(_/(1024*1024)).toFixed(1)}M`:`${(_/1024).toFixed(1)}K`:String(Math.floor(r?_/(1024*1024*1024):e?_/(1024*1024):_/1024)),h=" total used free shared buff/cache available",g=`Mem: ${u(s).padStart(12)} ${u(o).padStart(11)} ${u(i).padStart(11)} ${u(a).padStart(11)} ${u(c).padStart(11)} ${u(f).padStart(11)}`,y=`Swap: ${u(l).padStart(12)} ${u(0).padStart(11)} ${u(l).padStart(11)}`;return{stdout:[h,g,y].join(`
|
|
67
|
+
`),exitCode:0}}};var ku={name:"grep",description:"Search text patterns",category:"text",params:["[-i] [-v] [-n] [-r] <pattern> [file...]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:s})=>{let{flags:i,positionals:o}=zt(r,{flags:["-i","-v","-n","-r"]}),a=i.has("-i"),c=i.has("-v"),f=i.has("-n"),l=i.has("-r"),u=o[0],h=o.slice(1);if(!u)return{stderr:"grep: no pattern specified",exitCode:1};let g;try{let C=a?"mi":"m";g=new RegExp(u,C)}catch{return{stderr:`grep: invalid regex: ${u}`,exitCode:1}}let y=(C,L="")=>{let F=C.split(`
|
|
68
68
|
`),k=[];for(let K=0;K<F.length;K++){let ee=F[K]??"",O=g.test(ee);if(c?!O:O){let w=f?`${K+1}:`:"";k.push(`${L}${w}${ee}`)}}return k},_=C=>{if(!t.vfs.exists(C))return[];if(t.vfs.stat(C).type==="file")return[C];if(!l)return[];let F=[],k=K=>{for(let ee of t.vfs.list(K)){let O=`${K}/${ee}`;t.vfs.stat(O).type==="file"?F.push(O):k(O)}};return k(C),F},b=[];if(h.length===0){if(!s)return{stdout:"",exitCode:1};b.push(...y(s))}else{let C=h.flatMap(L=>{let F=le(e,L);return _(F).map(k=>({file:L,path:k}))});for(let{file:L,path:F}of C)try{$e(n,F,"grep");let k=t.vfs.readFile(F),K=C.length>1?`${L}:`:"";b.push(...y(k,K))}catch{return{stderr:`grep: ${L}: No such file or directory`,exitCode:1}}}return{stdout:b.length>0?b.join(`
|
|
69
|
-
`):"",exitCode:b.length>0?0:1}}};var
|
|
69
|
+
`):"",exitCode:b.length>0?0:1}}};var Bu={name:"groups",description:"Print group memberships",category:"system",params:["[user]"],run:({authUser:n,shell:t,args:e})=>{let r=e[0]??n;return{stdout:t.users.isSudoer(r)?`${r} sudo root`:r,exitCode:0}}};var Ru={name:"gzip",description:"Compress files",category:"archive",params:["<file>"],run:({shell:n,cwd:t,args:e})=>{let r=e[0];if(!r)return{stderr:"gzip: no file specified",exitCode:1};let s=le(t,r);try{return n.vfs.compressFile(s),{exitCode:0}}catch{return{stderr:`gzip: ${r}: No such file or directory`,exitCode:1}}}},Nu={name:"gunzip",description:"Decompress files",category:"archive",params:["<file>"],aliases:["zcat"],run:({shell:n,cwd:t,args:e})=>{let r=e[0];if(!r)return{stderr:"gunzip: no file specified",exitCode:1};let s=le(t,r);try{return n.vfs.decompressFile(s),{exitCode:0}}catch{return{stderr:`gunzip: ${r}: No such file or directory`,exitCode:1}}}};var Pu={name:"head",description:"Output first lines",category:"text",params:["[-n <lines>] [file...]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:s})=>{let i=en(r,["-n"]),o=typeof i=="string"?parseInt(i,10):10,a=r.filter(l=>!l.startsWith("-")&&l!==i),c=l=>l.split(`
|
|
70
70
|
`).slice(0,o).join(`
|
|
71
71
|
`);if(a.length===0)return{stdout:c(s??""),exitCode:0};let f=[];for(let l of a){let u=le(e,l);try{$e(n,u,"head"),f.push(c(t.vfs.readFile(u)))}catch{return{stderr:`head: ${l}: No such file or directory`,exitCode:1}}}return{stdout:f.join(`
|
|
72
|
-
`),exitCode:0}}};var
|
|
73
|
-
`)}function
|
|
74
|
-
`)}function
|
|
72
|
+
`),exitCode:0}}};var Tu=["navigation","files","text","archive","system","package","network","shell","users","misc"],Uu={navigation:"Navigation",files:"Files & Filesystem",text:"Text Processing",archive:"Archive & Compression",system:"System",package:"Package Management",network:"Network",shell:"Shell & Scripting",users:"Users & Permissions",misc:"Miscellaneous"},Du="\x1B[1m",Sn="\x1B[0m",Ym="\x1B[36m",zm="\x1B[33m",Ri="\x1B[2m",jm="\x1B[32m";function Lu(n,t){return n.length>=t?n:n+" ".repeat(t-n.length)}function Xm(n){let t=n.aliases?.length?` ${Ri}(${n.aliases.join(", ")})${Sn}`:"";return` ${Ym}${Lu(n.name,16)}${Sn}${t}${Lu("",(n.aliases?.length,0))} ${n.description??""}`}function Jm(n){let t={};for(let i of n){let o=i.category??"misc";t[o]||(t[o]=[]),t[o].push(i)}let e=[`${Du}Available commands${Sn}`,`${Ri}Type 'help <command>' for detailed usage.${Sn}`,""],r=[...Tu.filter(i=>t[i]),...Object.keys(t).filter(i=>!Tu.includes(i)).sort()];for(let i of r){let o=t[i];if(!o?.length)continue;e.push(`${zm}${Uu[i]??i}${Sn}`);let a=[...o].sort((c,f)=>c.name.localeCompare(f.name));for(let c of a)e.push(Xm(c));e.push("")}let s=n.length;return e.push(`${Ri}${s} commands available.${Sn}`),e.join(`
|
|
73
|
+
`)}function Zm(n){let t=[];if(t.push(`${Du}${n.name}${Sn} \u2014 ${n.description??"no description"}`),n.aliases?.length&&t.push(`${Ri}Aliases: ${n.aliases.join(", ")}${Sn}`),t.push(""),t.push(`${jm}Usage:${Sn}`),n.params.length)for(let r of n.params)t.push(` ${n.name} ${r}`);else t.push(` ${n.name}`);let e=Uu[n.category??"misc"]??n.category??"misc";return t.push(""),t.push(`${Ri}Category: ${e}${Sn}`),t.join(`
|
|
74
|
+
`)}function Ou(n){return{name:"help",description:"List all commands, or show usage for a specific command",category:"shell",params:["[command]"],run:({args:t})=>{let e=Ya();if(t[0]){let r=t[0].toLowerCase(),s=e.find(i=>i.name===r||i.aliases?.includes(r));return s?{stdout:Zm(s),exitCode:0}:{stderr:`help: no help entry for '${t[0]}'`,exitCode:1}}return{stdout:Jm(e),exitCode:0}}}}var Mu={name:"history",description:"Display command history",category:"shell",params:["[n]"],run:({args:n,shell:t})=>{let e="/virtual-env-js/.bash_history";if(!t.vfs.exists(e))return{stdout:"",exitCode:0};let s=t.vfs.readFile(e).split(`
|
|
75
75
|
`).filter(Boolean),i=n[0],o=i?parseInt(i,10):null,a=o&&!Number.isNaN(o)?s.slice(-o):s,c=s.length-a.length+1;return{stdout:a.map((l,u)=>`${String(c+u).padStart(5)} ${l}`).join(`
|
|
76
|
-
`),exitCode:0}}};var
|
|
77
|
-
`):
|
|
76
|
+
`),exitCode:0}}};var $u={name:"hostname",description:"Print hostname",category:"system",params:[],run:({hostname:n})=>({stdout:n,exitCode:0})};var Fu={name:"htop",description:"System monitor",category:"system",params:[],run:({mode:n})=>n==="exec"?{stderr:"htop: interactive terminal required",exitCode:1}:{openHtop:!0,exitCode:0}};var Hu={name:"id",description:"Print user identity",category:"system",params:["[user]"],run:({authUser:n,shell:t,args:e})=>{let r=e[0]??n,s=r==="root"?0:1e3,i=s,a=t.users.isSudoer(r)?`${i}(${r}),0(root)`:`${i}(${r})`;return{stdout:`uid=${s}(${r}) gid=${i}(${r}) groups=${a}`,exitCode:0}}};var Qu={name:"kill",description:"Send signal to process",category:"system",params:["[-9] <pid>"],run:({args:n})=>n.find(e=>!e.startsWith("-"))?{stdout:"",exitCode:0}:{stderr:"kill: no pid specified",exitCode:1}};var Wu={name:"ln",description:"Create links",category:"files",params:["[-s] <target> <link_name>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=ne(r,["-s","--symbolic"]),i=r.filter(l=>!l.startsWith("-")),[o,a]=i;if(!o||!a)return{stderr:"ln: missing operand",exitCode:1};let c=le(e,a),f=s?o:le(e,o);try{if($e(n,c,"ln"),s)t.vfs.symlink(f,c);else{let l=le(e,o);if($e(n,l,"ln"),!t.vfs.exists(l))return{stderr:`ln: ${o}: No such file or directory`,exitCode:1};let u=t.vfs.readFile(l);t.writeFileAsUser(n,c,u)}return{exitCode:0}}catch(l){return{stderr:`ln: ${l instanceof Error?l.message:String(l)}`,exitCode:1}}}};function eA(n,t){let e=t?"d":"-",s=[[256,"r"],[128,"w"],[64,"x"],[32,"r"],[16,"w"],[8,"x"],[4,"r"],[2,"w"],[1,"x"]].map(([i,o])=>n&i?o:"-").join("");return`${e}${s}`}function tA(n){return n.toISOString().replace("T"," ").slice(0,16)}var qu={name:"ls",description:"List directory contents",category:"navigation",params:["[-la] [path]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=ne(r,["-l","--long"]),i=ne(r,["-a","--all"]),o=mn(r,0,{flags:["-l","--long","-a","--all","-la","-al"]}),a=le(e,o??e);$e(n,a,"ls");let c=t.vfs.list(a).filter(l=>i||!l.startsWith("."));return{stdout:s?c.map(l=>{let u=le(a,l),h=t.vfs.stat(u),g=h.type==="file"?h.size:h.childrenCount;return`${eA(h.mode,h.type==="directory")} 1 ${g} ${tA(h.updatedAt)} ${l}${h.type==="directory"?"/":""}`}).join(`
|
|
77
|
+
`):nu(a,c,l=>t.vfs.stat(l)),exitCode:0}}};var Ku={name:"lsb_release",description:"Print distribution-specific information",category:"system",params:["[-a] [-i] [-d] [-r] [-c]"],run:({args:n,shell:t})=>{let e=t.properties?.os??"Fortune GNU/Linux x64",r="aurora",s="1.0";try{let u=t.vfs.readFile("/etc/os-release");for(let h of u.split(`
|
|
78
78
|
`))h.startsWith("PRETTY_NAME=")&&(e=h.slice(12).replace(/^"|"$/g,"").trim()),h.startsWith("VERSION_CODENAME=")&&(r=h.slice(17).trim()),h.startsWith("VERSION_ID=")&&(s=h.slice(11).replace(/^"|"$/g,"").trim())}catch{}let i=ne(n,["-a","--all"]),o=ne(n,["-i","--id"]),a=ne(n,["-d","--description"]),c=ne(n,["-r","--release"]),f=ne(n,["-c","--codename"]);if(i||n.length===0)return{stdout:["Distributor ID: Fortune",`Description: ${e}`,`Release: ${s}`,`Codename: ${r}`].join(`
|
|
79
79
|
`),exitCode:0};let l=[];return o&&l.push("Distributor ID: Fortune"),a&&l.push(`Description: ${e}`),c&&l.push(`Release: ${s}`),f&&l.push(`Codename: ${r}`),{stdout:l.join(`
|
|
80
|
-
`),exitCode:0}}};var
|
|
80
|
+
`),exitCode:0}}};var nA={ls:`LS(1) User Commands LS(1)
|
|
81
81
|
|
|
82
82
|
NAME
|
|
83
83
|
ls - list directory contents
|
|
@@ -202,156 +202,156 @@ OPTIONS
|
|
|
202
202
|
-z, --gzip filter the archive through gzip
|
|
203
203
|
-f, --file=ARCHIVE use archive file or device ARCHIVE
|
|
204
204
|
-v, --verbose verbosely list files processed
|
|
205
|
-
-t, --list list the contents of an archive`},
|
|
206
|
-
`)){if(!t.startsWith("PRETTY_NAME="))continue;return t.slice(12).trim().replace(/^"|"$/g,"")}}catch{return}}function
|
|
207
|
-
`)[0]?.trim();return!t||t.length===0?void 0:t}catch{return}}function
|
|
208
|
-
`)}var
|
|
209
|
-
`),exitCode:0};for(let e of n)if(e.includes("=")){let r=e.indexOf("=");t.vars[e.slice(0,r)]=e.slice(r+1)}return{exitCode:0}}};var
|
|
210
|
-
`};case"util":return{format:(...o)=>o.map(
|
|
205
|
+
-t, --list list the contents of an archive`},Vu={name:"man",description:"Interface to the system reference manuals",category:"shell",params:["<command>"],run:({args:n,shell:t})=>{let e=n[0];if(!e)return{stderr:"What manual page do you want?",exitCode:1};let r=`/usr/share/man/man1/${e}.1`;if(t.vfs.exists(r))return{stdout:t.vfs.readFile(r),exitCode:0};let s=nA[e.toLowerCase()];return s?{stdout:s,exitCode:0}:{stderr:`No manual entry for ${e}`,exitCode:16}}};var Gu={name:"mkdir",description:"Make directories",category:"files",params:["<dir>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{if(r.length===0)return{stderr:"mkdir: missing operand",exitCode:1};for(let s=0;s<r.length;s++){let i=mn(r,s);if(!i)return{stderr:"mkdir: missing operand",exitCode:1};let o=le(e,i);$e(n,o,"mkdir"),t.vfs.mkdir(o)}return{exitCode:0}}};var Yu={name:"mv",description:"Move or rename files",category:"files",params:["<source> <dest>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=r.filter(f=>!f.startsWith("-")),[i,o]=s;if(!i||!o)return{stderr:"mv: missing operand",exitCode:1};let a=le(e,i),c=le(e,o);try{if($e(n,a,"mv"),$e(n,c,"mv"),!t.vfs.exists(a))return{stderr:`mv: ${i}: No such file or directory`,exitCode:1};let f=t.vfs.exists(c)&&t.vfs.stat(c).type==="directory"?`${c}/${i.split("/").pop()}`:c;return t.vfs.move(a,f),{exitCode:0}}catch(f){return{stderr:`mv: ${f instanceof Error?f.message:String(f)}`,exitCode:1}}}};var zu=Vt(require("node:path"),1);var ju={name:"nano",description:"Text editor",category:"files",params:["<file>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=r[0];if(!s)return{stderr:"nano: missing file operand",exitCode:1};let i=le(e,s);$e(n,i,"nano");let o=t.vfs.exists(i)?t.vfs.readFile(i):"",a=zu.posix.basename(i)||"buffer",c=`/tmp/sshmimic-nano-${Date.now()}-${a}.tmp`;return{openEditor:{targetPath:i,tempPath:c,initialContent:o},exitCode:0}}};var On=require("node:fs"),Mt=Vt(require("node:os"),1),rd=Vt(require("node:path"),1);function rA(n){let t=Math.max(1,Math.floor(n/60)),e=Math.floor(t/1440),r=Math.floor(t%1440/60),s=t%60,i=[];return e>0&&i.push(`${e} day${e>1?"s":""}`),r>0&&i.push(`${r} hour${r>1?"s":""}`),(s>0||i.length===0)&&i.push(`${s} min${s>1?"s":""}`),i.join(", ")}function Xu(n){return`\x1B[${n}m \x1B[0m`}function iA(){let n=[40,41,42,43,44,45,46,47].map(Xu).join(""),t=[100,101,102,103,104,105,106,107].map(Xu).join("");return[n,t]}function Ju(n,t,e){if(n.trim().length===0)return n;let r={r:255,g:255,b:255},s={r:168,g:85,b:247},i=e<=1?0:t/(e-1),o=Math.round(r.r+(s.r-r.r)*i),a=Math.round(r.g+(s.g-r.g)*i),c=Math.round(r.b+(s.b-r.b)*i);return`\x1B[38;2;${o};${a};${c}m${n}\x1B[0m`}function sA(n){if(n.trim().length===0)return n;let t=n.indexOf(":");if(t===-1)return n.includes("@")?Zu(n):n;let e=n.substring(0,t+1),r=n.substring(t+1);return Zu(e)+r}function Zu(n){let t=new RegExp("\x1B\\[[\\d;]*m","g"),e=n.replace(t,"");if(e.trim().length===0)return n;let r={r:255,g:255,b:255},s={r:168,g:85,b:247},i="";for(let o=0;o<e.length;o+=1){let a=e.length<=1?0:o/(e.length-1),c=Math.round(r.r+(s.r-r.r)*a),f=Math.round(r.g+(s.g-r.g)*a),l=Math.round(r.b+(s.b-r.b)*a);i+=`\x1B[38;2;${c};${f};${l}m${e[o]}\x1B[0m`}return i}function ed(n){return Math.max(0,Math.round(n/(1024*1024)))}function td(){try{let n=(0,On.readFileSync)("/etc/os-release","utf8");for(let t of n.split(`
|
|
206
|
+
`)){if(!t.startsWith("PRETTY_NAME="))continue;return t.slice(12).trim().replace(/^"|"$/g,"")}}catch{return}}function nd(n){try{let t=(0,On.readFileSync)(n,"utf8").split(`
|
|
207
|
+
`)[0]?.trim();return!t||t.length===0?void 0:t}catch{return}}function oA(n){let t=nd("/sys/devices/virtual/dmi/id/sys_vendor"),e=nd("/sys/devices/virtual/dmi/id/product_name");return t&&e?`${t} ${e}`:e||n}function aA(){let n=["/var/lib/dpkg/status","/usr/local/var/lib/dpkg/status"];for(let t of n)if((0,On.existsSync)(t))try{return(0,On.readFileSync)(t,"utf8").match(/^Package:\s+/gm)?.length??0}catch{}}function cA(){let n=["/snap","/var/lib/snapd/snaps"];for(let t of n)if((0,On.existsSync)(t))try{return(0,On.readdirSync)(t,{withFileTypes:!0}).filter(s=>s.isDirectory()).length}catch{}}function fA(){let n=aA(),t=cA();return n!==void 0&&t!==void 0?`${n} (dpkg), ${t} (snap)`:n!==void 0?`${n} (dpkg)`:t!==void 0?`${t} (snap)`:"n/a"}function lA(){let n=Mt.cpus();if(n.length===0)return"unknown";let t=n[0];if(!t)return"unknown";let e=(t.speed/1e3).toFixed(2);return`${t.model} (${n.length}) @ ${e}GHz`}function uA(n){return!n||n.trim().length===0?"unknown":rd.posix.basename(n.trim())}function dA(n){let t=Mt.totalmem(),e=Mt.freemem(),r=Math.max(0,t-e),s=n.shellProps,i=process.uptime();return n.uptimeSeconds===void 0&&(n.uptimeSeconds=Math.round(i)),{user:n.user,host:n.host,osName:s?.os??n.osName??`${td()??Mt.type()} ${Mt.arch()}`,kernel:s?.kernel??n.kernel??Mt.release(),uptimeSeconds:n.uptimeSeconds??Mt.uptime(),packages:n.packages??fA(),shell:uA(n.shell),shellProps:n.shellProps??{kernel:n.kernel??Mt.release(),os:n.osName??`${td()??Mt.type()} ${Mt.arch()}`,arch:Mt.arch()},resolution:n.resolution??"n/a (ssh)",terminal:n.terminal??"unknown",cpu:n.cpu??lA(),gpu:n.gpu??"n/a",memoryUsedMiB:n.memoryUsedMiB??ed(r),memoryTotalMiB:n.memoryTotalMiB??ed(t)}}function id(n){let t=dA(n),e=rA(t.uptimeSeconds),r=iA(),s=[" .. .:. "," .::.. .. .. ",". .... ... .. ",": .... .:. .. ",": .:.:........:. .. ",": .. ",". : ",". : ",".. : "," :. .. "," .. .. "," :-. :: "," .:. :. "," ..: ... "," ..: :.. "," :... :...."," .. ...."," . .. "," .:. .: "," :. .. "," ::. .. ","..... ..:... ","...:. .. ",".:...:. ::. .. "," ... ..:::::.. ..:::::::.. "],i=[`${t.user}@${t.host}`,"-------------------------",`OS: ${t.osName}`,`Host: ${oA(t.host)}`,`Kernel: ${t.kernel}`,`Uptime: ${e}`,`Packages: ${t.packages}`,`Shell: ${t.shell}`,`Resolution: ${t.resolution}`,`Terminal: ${t.terminal}`,`CPU: ${t.cpu}`,`GPU: ${t.gpu}`,`Memory: ${t.memoryUsedMiB}MiB / ${t.memoryTotalMiB}MiB`,"",r[0],r[1]],o=Math.max(s.length,i.length),a=[];for(let c=0;c<o;c+=1){let f=s[c]??"",l=i[c]??"";if(l.length>0){let u=Ju(f.padEnd(31," "),c,s.length),h=sA(l);a.push(`${u} ${h}`);continue}a.push(Ju(f,c,s.length))}return a.join(`
|
|
208
|
+
`)}var za={PATH:"/usr/local/bin:/usr/bin:/bin",HOME:"/home/user",SHELL:"/bin/sh",TERM:"xterm-256color",USER:"user"};function sd(n){return za.USER=n,za.HOME=`/home/${n}`,{...za}}var od={name:"set",description:"Display or set shell variables",category:"shell",params:["[VAR=value]"],run:({args:n,env:t})=>{if(n.length===0)return{stdout:Object.entries(t.vars).map(([r,s])=>`${r}=${s}`).join(`
|
|
209
|
+
`),exitCode:0};for(let e of n)if(e.includes("=")){let r=e.indexOf("=");t.vars[e.slice(0,r)]=e.slice(r+1)}return{exitCode:0}}};var ad={name:"neofetch",description:"System info display",category:"system",params:["[--off]"],run:({args:n,authUser:t,hostname:e,shell:r})=>{let s=sd(t);return ne(n,"--help")?{stdout:"Usage: neofetch [--off]",exitCode:0}:ne(n,"--off")?{stdout:`${t}@${e}`,exitCode:0}:{stdout:id({user:t,host:e,shell:s.SHELL,shellProps:r.properties,terminal:s.TERM,uptimeSeconds:Math.floor((Date.now()-r.startTime)/1e3),packages:`${r.packageManager?.installedCount()??0} (dpkg)`}),exitCode:0}}};var ja=Vt(require("node:vm"),1);var Os="v18.19.0",cd={node:Os,npm:"9.2.0",v8:"10.2.154.26-node.22"};function hA(n,t){let e={version:Os,versions:cd,platform:"linux",arch:"x64",env:{NODE_ENV:"production",HOME:"/root",PATH:"/usr/local/bin:/usr/bin:/bin"},argv:["node"],stdout:{write:i=>(n.push(i),!0)},stderr:{write:i=>(t.push(i),!0)},exit:(i=0)=>{throw new Ms(i)},cwd:()=>"/root",hrtime:()=>[0,0]},r={log:(...i)=>n.push(i.map(wn).join(" ")),error:(...i)=>t.push(i.map(wn).join(" ")),warn:(...i)=>t.push(i.map(wn).join(" ")),info:(...i)=>n.push(i.map(wn).join(" ")),dir:i=>n.push(wn(i))},s=i=>{switch(i){case"path":return{join:(...o)=>o.join("/").replace(/\/+/g,"/"),resolve:(...o)=>`/${o.join("/").replace(/^\/+/,"")}`,dirname:o=>o.split("/").slice(0,-1).join("/")||"/",basename:o=>o.split("/").pop()??"",extname:o=>{let a=o.split("/").pop()??"",c=a.lastIndexOf(".");return c>0?a.slice(c):""},sep:"/",delimiter:":"};case"os":return{platform:()=>"linux",arch:()=>"x64",type:()=>"Linux",hostname:()=>"fortune-vm",homedir:()=>"/root",tmpdir:()=>"/tmp",EOL:`
|
|
210
|
+
`};case"util":return{format:(...o)=>o.map(wn).join(" "),inspect:o=>wn(o)};case"fs":case"fs/promises":throw new Error(`Cannot require '${i}': filesystem access not available in virtual runtime`);case"child_process":case"net":case"http":case"https":throw new Error(`Cannot require '${i}': not available in virtual runtime`);default:throw new Error(`Cannot find module '${i}'`)}};return s.resolve=i=>{throw new Error(`Cannot resolve '${i}'`)},s.cache={},s.extensions={},ja.default.createContext({console:r,process:e,require:s,Math,JSON,Object,Array,String,Number,Boolean,Symbol,Date,RegExp,Error,TypeError,RangeError,SyntaxError,Promise,Map,Set,WeakMap,WeakSet,parseInt,parseFloat,isNaN,isFinite,encodeURIComponent,decodeURIComponent,encodeURI,decodeURI,setTimeout:()=>{},clearTimeout:()=>{},setInterval:()=>{},clearInterval:()=>{},queueMicrotask:()=>{},globalThis:void 0,undefined:void 0,Infinity:1/0,NaN:NaN})}var Ms=class{constructor(t){this.code=t}code};function wn(n){if(n===null)return"null";if(n===void 0)return"undefined";if(typeof n=="string")return n;if(typeof n=="function")return`[Function: ${n.name||"(anonymous)"}]`;if(Array.isArray(n))return`[ ${n.map(wn).join(", ")} ]`;if(n instanceof Error)return`${n.name}: ${n.message}`;if(typeof n=="object")try{return`{ ${Object.entries(n).map(([e,r])=>`${e}: ${wn(r)}`).join(", ")} }`}catch{return"[Object]"}return String(n)}function $s(n){let t=[],e=[],r=hA(t,e),s=0;try{let i=ja.default.runInContext(n,r,{timeout:5e3});i!==void 0&&t.length===0&&t.push(wn(i))}catch(i){i instanceof Ms?s=i.code:i instanceof Error?(e.push(`${i.name}: ${i.message}`),s=1):(e.push(String(i)),s=1)}return{stdout:t.length?`${t.join(`
|
|
211
211
|
`)}
|
|
212
212
|
`:"",stderr:e.length?`${e.join(`
|
|
213
213
|
`)}
|
|
214
|
-
`:"",exitCode:s}}function
|
|
215
|
-
`)&&!t.startsWith("const ")&&!t.startsWith("let ")&&!t.startsWith("var ")&&!t.startsWith("function ")&&!t.startsWith("class ")&&!t.startsWith("if ")&&!t.startsWith("for ")&&!t.startsWith("while ")&&!t.startsWith("import ")&&!t.startsWith("//")
|
|
214
|
+
`:"",exitCode:s}}function pA(n){let t=n.trim();return!t.includes(`
|
|
215
|
+
`)&&!t.startsWith("const ")&&!t.startsWith("let ")&&!t.startsWith("var ")&&!t.startsWith("function ")&&!t.startsWith("class ")&&!t.startsWith("if ")&&!t.startsWith("for ")&&!t.startsWith("while ")&&!t.startsWith("import ")&&!t.startsWith("//")?$s(t):$s(`(async () => { ${n} })()`)}var fd={name:"node",description:"JavaScript runtime (virtual)",category:"system",params:["[--version] [-e <expr>] [-p <expr>] [file]"],run:({args:n,shell:t,cwd:e})=>{if(!t.packageManager.isInstalled("nodejs"))return{stderr:`bash: node: command not found
|
|
216
216
|
Hint: install it with: apt install nodejs
|
|
217
|
-
`,exitCode:127};if(ne(n,["--version","-v"]))return{stdout:`${
|
|
218
|
-
`,exitCode:0};if(ne(n,["--versions"]))return{stdout:`${JSON.stringify(
|
|
217
|
+
`,exitCode:127};if(ne(n,["--version","-v"]))return{stdout:`${Os}
|
|
218
|
+
`,exitCode:0};if(ne(n,["--versions"]))return{stdout:`${JSON.stringify(cd,null,2)}
|
|
219
219
|
`,exitCode:0};let r=n.findIndex(o=>o==="-e"||o==="--eval");if(r!==-1){let o=n[r+1];if(!o)return{stderr:`node: -e requires an argument
|
|
220
|
-
`,exitCode:1};let{stdout:a,stderr:c,exitCode:f}
|
|
221
|
-
`,exitCode:1};let{stdout:a,stderr:c,exitCode:f}
|
|
220
|
+
`,exitCode:1};let{stdout:a,stderr:c,exitCode:f}=$s(o);return{stdout:a||void 0,stderr:c||void 0,exitCode:f}}let s=n.findIndex(o=>o==="-p"||o==="--print");if(s!==-1){let o=n[s+1];if(!o)return{stderr:`node: -p requires an argument
|
|
221
|
+
`,exitCode:1};let{stdout:a,stderr:c,exitCode:f}=$s(o);return{stdout:a||(f===0?`
|
|
222
222
|
`:void 0),stderr:c||void 0,exitCode:f}}let i=n.find(o=>!o.startsWith("-"));if(i){let o=le(e,i);if(!t.vfs.exists(o))return{stderr:`node: cannot open file '${i}': No such file or directory
|
|
223
|
-
`,exitCode:1};let a=t.vfs.readFile(o),{stdout:c,stderr:f,exitCode:l}=
|
|
224
|
-
`),exitCode:0}}};var
|
|
223
|
+
`,exitCode:1};let a=t.vfs.readFile(o),{stdout:c,stderr:f,exitCode:l}=pA(a);return{stdout:c||void 0,stderr:f||void 0,exitCode:l}}return{stdout:[`Welcome to Node.js ${Os}.`,'Type ".exit" to exit the REPL.',"> "].join(`
|
|
224
|
+
`),exitCode:0}}};var Fs="9.2.0",gA="18.19.0",ld={name:"npm",description:"Node.js package manager (virtual)",category:"system",params:["<command> [args]"],run:({args:n,shell:t})=>{if(!t.packageManager.isInstalled("npm"))return{stderr:`bash: npm: command not found
|
|
225
225
|
Hint: install it with: apt install npm
|
|
226
|
-
`,exitCode:127};if(ne(n,["--version","-v"]))return{stdout:`${
|
|
227
|
-
`,exitCode:0};let e=n[0]?.toLowerCase();switch(e){case"version":case"-version":return{stdout:`{ npm: '${
|
|
226
|
+
`,exitCode:127};if(ne(n,["--version","-v"]))return{stdout:`${Fs}
|
|
227
|
+
`,exitCode:0};let e=n[0]?.toLowerCase();switch(e){case"version":case"-version":return{stdout:`{ npm: '${Fs}', node: '${gA}', v8: '10.2.154.26' }
|
|
228
228
|
`,exitCode:0};case"install":case"i":case"add":return{stderr:`npm warn: package installation is not available in the virtual runtime.
|
|
229
229
|
npm warn: This environment simulates npm CLI behaviour only.
|
|
230
230
|
`,exitCode:1};case"run":case"exec":case"x":return{stderr:`npm error: script execution is not available in the virtual runtime.
|
|
231
231
|
`,exitCode:1};case"init":return{stdout:`Wrote to /home/user/package.json
|
|
232
232
|
`,exitCode:0};case"list":case"ls":return{stdout:`${e==="ls"||e==="list"?"virtual-env@1.0.0":""}
|
|
233
233
|
\u2514\u2500\u2500 (empty)
|
|
234
|
-
`,exitCode:0};case"help":case void 0:return{stdout:`${[`npm ${
|
|
234
|
+
`,exitCode:0};case"help":case void 0:return{stdout:`${[`npm ${Fs}`,"","Usage: npm <command>","","Commands:"," install (not available in virtual runtime)"," run (not available in virtual runtime)"," exec (not available in virtual runtime)"," list List installed packages"," version Print versions"," --version Print npm version"].join(`
|
|
235
235
|
`)}
|
|
236
236
|
`,exitCode:0};default:return{stderr:`npm error: unknown command: ${e}
|
|
237
|
-
`,exitCode:1}}}},
|
|
237
|
+
`,exitCode:1}}}},ud={name:"npx",description:"Node.js package runner (virtual)",category:"system",params:["<package> [args]"],run:({args:n,shell:t})=>t.packageManager.isInstalled("npm")?ne(n,["--version"])?{stdout:`${Fs}
|
|
238
238
|
`,exitCode:0}:{stderr:`npx: package execution is not available in the virtual runtime.
|
|
239
239
|
`,exitCode:1}:{stderr:`bash: npx: command not found
|
|
240
240
|
Hint: install it with: apt install npm
|
|
241
|
-
`,exitCode:127}};var
|
|
242
|
-
`),exitCode:0}}};function
|
|
243
|
-
`,s+=2;continue;case"t":r+=" ",s+=2;continue;case"r":r+="\r",s+=2;continue;case"\\":r+="\\",s+=2;continue;case"a":r+="\x07",s+=2;continue;case"b":r+="\b",s+=2;continue;case"f":r+="\f",s+=2;continue;case"v":r+="\v",s+=2;continue;default:r+=n[s],s++;continue}if(n[s]==="%"&&s+1<n.length){let i=s+1;for(n[i]==="-"&&i++;i<n.length&&/\d/.test(n[i]);)i++;if(n[i]===".")for(i++;i<n.length&&/\d/.test(n[i]);)i++;let o=n[i],a=t[e++]??"";switch(o){case"s":r+=a;break;case"d":case"i":r+=String(parseInt(a,10)||0);break;case"f":r+=String(parseFloat(a)||0);break;case"o":r+=(parseInt(a,10)||0).toString(8);break;case"x":r+=(parseInt(a,10)||0).toString(16);break;case"X":r+=(parseInt(a,10)||0).toString(16).toUpperCase();break;case"%":r+="%",e--;break;default:r+=n[s],s++;continue}s=i+1;continue}r+=n[s],s++}return r}var
|
|
241
|
+
`,exitCode:127}};var dd={name:"passwd",description:"Change user password",category:"users",params:["<username> <password>"],run:async({authUser:n,args:t,shell:e})=>{let[r,s]=t;return!r||!s?{stderr:"passwd: usage: passwd <username> <password>",exitCode:1}:n!=="root"&&n!==r?{stderr:"passwd: permission denied",exitCode:1}:(await e.users.setPassword(r,s),{stdout:`passwd: password updated for '${r}'`,exitCode:0})}};var hd={name:"ping",description:"Send ICMP ECHO_REQUEST (mock)",category:"network",params:["[-c <count>] <host>"],run:({args:n})=>{let{flagsWithValues:t,positionals:e}=zt(n,{flagsWithValue:["-c","-i","-W"]}),r=e[0]??"localhost",s=t.get("-c"),i=s?Math.max(1,parseInt(s,10)||4):4,o=[`PING ${r}: 56 data bytes`];for(let a=0;a<i;a++){let c=(Math.random()*10+1).toFixed(3);o.push(`64 bytes from ${r}: icmp_seq=${a} ttl=64 time=${c} ms`)}return o.push(`--- ${r} ping statistics ---`),o.push(`${i} packets transmitted, ${i} received, 0% packet loss`),{stdout:o.join(`
|
|
242
|
+
`),exitCode:0}}};function mA(n,t){let e=0,r="",s=0;for(;s<n.length;){if(n[s]==="\\"&&s+1<n.length)switch(n[s+1]){case"n":r+=`
|
|
243
|
+
`,s+=2;continue;case"t":r+=" ",s+=2;continue;case"r":r+="\r",s+=2;continue;case"\\":r+="\\",s+=2;continue;case"a":r+="\x07",s+=2;continue;case"b":r+="\b",s+=2;continue;case"f":r+="\f",s+=2;continue;case"v":r+="\v",s+=2;continue;default:r+=n[s],s++;continue}if(n[s]==="%"&&s+1<n.length){let i=s+1;for(n[i]==="-"&&i++;i<n.length&&/\d/.test(n[i]);)i++;if(n[i]===".")for(i++;i<n.length&&/\d/.test(n[i]);)i++;let o=n[i],a=t[e++]??"";switch(o){case"s":r+=a;break;case"d":case"i":r+=String(parseInt(a,10)||0);break;case"f":r+=String(parseFloat(a)||0);break;case"o":r+=(parseInt(a,10)||0).toString(8);break;case"x":r+=(parseInt(a,10)||0).toString(16);break;case"X":r+=(parseInt(a,10)||0).toString(16).toUpperCase();break;case"%":r+="%",e--;break;default:r+=n[s],s++;continue}s=i+1;continue}r+=n[s],s++}return r}var pd={name:"printf",description:"Format and print data",category:"shell",params:["<format> [args...]"],run:({args:n})=>{let t=n[0];return t?{stdout:mA(t,n.slice(1)),exitCode:0}:{stderr:"printf: missing format string",exitCode:1}}};var gd={name:"ps",description:"Report process status",category:"system",params:["[-a] [-u] [-x] [aux]"],run:({authUser:n,shell:t,args:e})=>{let r=t.users.listActiveSessions(),s=ne(e,["-u"])||e.includes("u")||e.includes("aux")||e.includes("au"),i=ne(e,["-a","-x"])||e.includes("a")||e.includes("aux");if(s){let l=["USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND"],u=1e3;for(let h of r){let g=h.username.padEnd(10).slice(0,10),y=(Math.random()*.5).toFixed(1),_=Math.floor(Math.random()*2e4+5e3),b=Math.floor(Math.random()*5e3+1e3);l.push(`${g} ${String(u).padStart(6)} 0.0 ${y.padStart(4)} ${String(_).padStart(6)} ${String(b).padStart(5)} ${h.tty.padEnd(8)} Ss 00:00 0:00 bash`),u++}return l.push(`root ${String(u).padStart(6)} 0.0 0.0 0 0 ? S 00:00 0:00 ps`),{stdout:l.join(`
|
|
244
244
|
`),exitCode:0}}let a=[" PID TTY TIME CMD"],c=1e3;for(let f of r)!i&&f.username!==n||(a.push(`${String(c).padStart(5)} ${f.tty.padEnd(12)} 00:00:00 ${f.username===n?"bash":`bash (${f.username})`}`),c++);return a.push(`${String(c).padStart(5)} pts/0 00:00:00 ps`),{stdout:a.join(`
|
|
245
|
-
`),exitCode:0}}};var
|
|
246
|
-
`],["curdir","."],["pardir",".."]]);return e.__methods__={getcwd:()=>n,getenv:r=>typeof r=="string"?process.env[r]??V:V,path:
|
|
247
|
-
`],["name","posix"]]);return e._cwd=n,t._cwd=n,e.path=t,e}function
|
|
245
|
+
`),exitCode:0}}};var md={name:"pwd",description:"Print working directory",category:"navigation",params:[],run:({cwd:n})=>({stdout:n,exitCode:0})};var AA="Python 3.11.2";var Hs="3.11.2 (default, Mar 13 2023, 12:18:29) [GCC 12.2.0]",V={__pytype__:"none"};function mt(n=[]){return{__pytype__:"dict",data:new Map(n)}}function Xa(n,t,e=1){return{__pytype__:"range",start:n,stop:t,step:e}}function ht(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="dict"}function qr(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="range"}function In(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="func"}function Ja(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="class"}function Ni(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="instance"}function Mn(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="none"}function kt(n){return n===null||Mn(n)?"None":n===!0?"True":n===!1?"False":typeof n=="number"?Number.isInteger(n)?String(n):n.toPrecision(12).replace(/\.?0+$/,""):typeof n=="string"?`'${n.replace(/'/g,"\\'")}'`:Array.isArray(n)?`[${n.map(kt).join(", ")}]`:ht(n)?`{${[...n.data.entries()].map(([t,e])=>`'${t}': ${kt(e)}`).join(", ")}}`:qr(n)?`range(${n.start}, ${n.stop}${n.step!==1?`, ${n.step}`:""})`:In(n)?`<function ${n.name} at 0x...>`:Ja(n)?`<class '${n.name}'>`:Ni(n)?`<${n.cls.name} object at 0x...>`:String(n)}function Ne(n){return n===null||Mn(n)?"None":n===!0?"True":n===!1?"False":typeof n=="number"?Number.isInteger(n)?String(n):n.toPrecision(12).replace(/\.?0+$/,""):typeof n=="string"?n:Array.isArray(n)?`[${n.map(kt).join(", ")}]`:ht(n)?`{${[...n.data.entries()].map(([t,e])=>`'${t}': ${kt(e)}`).join(", ")}}`:qr(n)?`range(${n.start}, ${n.stop}${n.step!==1?`, ${n.step}`:""})`:kt(n)}function on(n){return n===null||Mn(n)?!1:typeof n=="boolean"?n:typeof n=="number"?n!==0:typeof n=="string"||Array.isArray(n)?n.length>0:ht(n)?n.data.size>0:qr(n)?Ed(n)>0:!0}function Ed(n){if(n.step===0)return 0;let t=Math.ceil((n.stop-n.start)/n.step);return Math.max(0,t)}function EA(n){let t=[];for(let e=n.start;(n.step>0?e<n.stop:e>n.stop)&&(t.push(e),!(t.length>1e4));e+=n.step);return t}function vt(n){if(Array.isArray(n))return n;if(typeof n=="string")return[...n];if(qr(n))return EA(n);if(ht(n))return[...n.data.keys()];throw new gt("TypeError",`'${fr(n)}' object is not iterable`)}function fr(n){return n===null||Mn(n)?"NoneType":typeof n=="boolean"?"bool":typeof n=="number"?Number.isInteger(n)?"int":"float":typeof n=="string"?"str":Array.isArray(n)?"list":ht(n)?"dict":qr(n)?"range":In(n)?"function":Ja(n)?"type":Ni(n)?n.cls.name:"object"}var gt=class{constructor(t,e){this.type=t;this.message=e}type;message;toString(){return`${this.type}: ${this.message}`}},Wr=class{constructor(t){this.value=t}value},Pi=class{},Ti=class{},Li=class{constructor(t){this.code=t}code};function _A(n){let t=new Map,e=mt([["sep","/"],["linesep",`
|
|
246
|
+
`],["curdir","."],["pardir",".."]]);return e.__methods__={getcwd:()=>n,getenv:r=>typeof r=="string"?process.env[r]??V:V,path:mt([["join",V],["exists",V],["dirname",V],["basename",V]]),listdir:()=>[]},t.set("__builtins__",V),t.set("__name__","__main__"),t.set("__cwd__",n),t}function yA(n){let t=mt([["sep","/"],["curdir","."]]),e=mt([["sep","/"],["linesep",`
|
|
247
|
+
`],["name","posix"]]);return e._cwd=n,t._cwd=n,e.path=t,e}function bA(){return mt([["version",Hs],["version_info",mt([["major",3],["minor",11],["micro",2]].map(([n,t])=>[n,t]))],["platform","linux"],["executable","/usr/bin/python3"],["prefix","/usr"],["path",["/usr/lib/python3.11","/usr/lib/python3.11/lib-dynload"]],["argv",[""]],["maxsize",9007199254740991]])}function xA(){return mt([["pi",Math.PI],["e",Math.E],["tau",Math.PI*2],["inf",1/0],["nan",NaN],["sqrt",V],["floor",V],["ceil",V],["log",V],["pow",V],["sin",V],["cos",V],["tan",V],["fabs",V],["factorial",V]])}function SA(){return mt([["dumps",V],["loads",V]])}function wA(){return mt([["match",V],["search",V],["findall",V],["sub",V],["split",V],["compile",V]])}var Ad={os:yA,sys:()=>bA(),math:()=>xA(),json:()=>SA(),re:()=>wA(),random:()=>mt([["random",V],["randint",V],["choice",V],["shuffle",V]]),time:()=>mt([["time",V],["sleep",V],["ctime",V]]),datetime:()=>mt([["datetime",V],["date",V],["timedelta",V]]),collections:()=>mt([["Counter",V],["defaultdict",V],["OrderedDict",V]]),itertools:()=>mt([["chain",V],["product",V],["combinations",V],["permutations",V]]),functools:()=>mt([["reduce",V],["partial",V],["lru_cache",V]]),string:()=>mt([["ascii_letters","abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"],["digits","0123456789"],["punctuation","!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"]])},Qs=class{constructor(t){this.cwd=t}cwd;output=[];stderr=[];modules=new Map;getOutput(){return this.output.join(`
|
|
248
248
|
`)+(this.output.length?`
|
|
249
249
|
`:"")}getStderr(){return this.stderr.join(`
|
|
250
250
|
`)+(this.stderr.length?`
|
|
251
251
|
`:"")}splitArgs(t){let e=[],r=0,s="",i=!1,o="";for(let a=0;a<t.length;a++){let c=t[a];i?(s+=c,c===o&&t[a-1]!=="\\"&&(i=!1)):c==='"'||c==="'"?(i=!0,o=c,s+=c):"([{".includes(c)?(r++,s+=c):")]}".includes(c)?(r--,s+=c):c===","&&r===0?(e.push(s.trim()),s=""):s+=c}return s.trim()&&e.push(s.trim()),e}pyEval(t,e){if(t=t.trim(),!t||t==="None")return V;if(t==="True")return!0;if(t==="False")return!1;if(t==="...")return V;if(/^-?\d+$/.test(t))return parseInt(t,10);if(/^-?\d+\.\d*$/.test(t))return parseFloat(t);if(/^0x[0-9a-fA-F]+$/.test(t))return parseInt(t,16);if(/^0o[0-7]+$/.test(t))return parseInt(t.slice(2),8);if(/^('''[\s\S]*'''|"""[\s\S]*""")$/.test(t))return t.slice(3,-3);if(/^(['"])(.*)\1$/s.test(t))return t.slice(1,-1).replace(/\\n/g,`
|
|
252
|
-
`).replace(/\\t/g," ").replace(/\\r/g,"\r").replace(/\\\\/g,"\\").replace(/\\'/g,"'").replace(/\\"/g,'"');let r=t.match(/^f(['"])([\s\S]*)\1$/);if(r){let f=r[2];return f=f.replace(/\{([^{}]+)\}/g,(l,u)=>{try{return
|
|
253
|
-
`);case"join":return vt(r[0]??[]).map(
|
|
254
|
-
`.replace(/\\n/g,"")),V;case"input":return this.output.push(
|
|
255
|
-
`);this.execLines(r,0,e)}execLines(t,e,r){let s=e;for(;s<t.length;){let i=t[s];if(!i.trim()||i.trim().startsWith("#")){s++;continue}s=this.execStatement(t,s,r)}return s}execBlock(t,e){try{this.execLines(t,0,e)}catch(r){if(r instanceof
|
|
252
|
+
`).replace(/\\t/g," ").replace(/\\r/g,"\r").replace(/\\\\/g,"\\").replace(/\\'/g,"'").replace(/\\"/g,'"');let r=t.match(/^f(['"])([\s\S]*)\1$/);if(r){let f=r[2];return f=f.replace(/\{([^{}]+)\}/g,(l,u)=>{try{return Ne(this.pyEval(u.trim(),e))}catch{return`{${u}}`}}),f}let s=t.match(/^b(['"])(.*)\1$/s);if(s)return s[2];if(t.startsWith("[")&&t.endsWith("]")){let f=t.slice(1,-1).trim();if(!f)return[];let l=f.match(/^(.+?)\s+for\s+(\w+)\s+in\s+(.+?)(?:\s+if\s+(.+))?$/);if(l){let[,u,h,g,y]=l,_=vt(this.pyEval(g.trim(),e)),b=[];for(let C of _){let L=new Map(e);L.set(h,C),!(y&&!on(this.pyEval(y,L)))&&b.push(this.pyEval(u.trim(),L))}return b}return this.splitArgs(f).map(u=>this.pyEval(u,e))}if(t.startsWith("(")&&t.endsWith(")")){let f=t.slice(1,-1).trim();if(!f)return[];let l=this.splitArgs(f);return l.length===1&&!f.endsWith(",")?this.pyEval(l[0],e):l.map(u=>this.pyEval(u,e))}if(t.startsWith("{")&&t.endsWith("}")){let f=t.slice(1,-1).trim();if(!f)return mt();let l=mt();for(let u of this.splitArgs(f)){let h=u.indexOf(":");if(h===-1)continue;let g=Ne(this.pyEval(u.slice(0,h).trim(),e)),y=this.pyEval(u.slice(h+1).trim(),e);l.data.set(g,y)}return l}let i=t.match(/^not\s+(.+)$/);if(i)return!on(this.pyEval(i[1],e));let o=[["or"],["and"],["in","not in","is not","is","==","!=","<=",">=","<",">"],["+","-"],["**"],["*","//","/","%"]];for(let f of o){let l=this.tryBinaryOp(t,f,e);if(l!==void 0)return l}if(t.startsWith("-")){let f=this.pyEval(t.slice(1),e);if(typeof f=="number")return-f}if(process.env.PY_DEBUG&&console.error("eval:",JSON.stringify(t)),t.endsWith("]")&&!t.startsWith("[")){let f=this.findMatchingBracket(t,"[");if(f!==-1){let l=this.pyEval(t.slice(0,f),e),u=t.slice(f+1,-1);return this.subscript(l,u,e)}}let a=t.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*\(([\s\S]*)\)$/);if(a){let[,f,l]=a,u=(l?.trim()?this.splitArgs(l):[]).map(h=>this.pyEval(h,e));return this.callBuiltin(f,u,e)}let c=this.findDotAccess(t);if(c){let{objExpr:f,attr:l,callPart:u}=c,h=this.pyEval(f,e);if(u!==void 0){let g=u.slice(1,-1),y=g.trim()?this.splitArgs(g).map(_=>this.pyEval(_,e)):[];return this.callMethod(h,l,y,e)}return this.getAttr(h,l,e)}if(/^[A-Za-z_][A-Za-z0-9_]*$/.test(t)){if(e.has(t))return e.get(t);throw new gt("NameError",`name '${t}' is not defined`)}if(/^[A-Za-z_][A-Za-z0-9_.]+$/.test(t)){let f=t.split("."),l=e.get(f[0])??(()=>{throw new gt("NameError",`name '${f[0]}' is not defined`)})();for(let u of f.slice(1))l=this.getAttr(l,u,e);return l}return V}findMatchingBracket(t,e){let r=e==="["?"]":e==="("?")":"}",s=0;for(let i=t.length-1;i>=0;i--)if(t[i]===r&&s++,t[i]===e&&(s--,s===0))return i;return-1}findDotAccess(t){let e=0,r=!1,s="";for(let i=t.length-1;i>0;i--){let o=t[i];if(r){o===s&&t[i-1]!=="\\"&&(r=!1);continue}if(o==='"'||o==="'"){r=!0,s=o;continue}if(")]}".includes(o)){e++;continue}if("([{".includes(o)){e--;continue}if(e!==0||o!==".")continue;let a=t.slice(0,i).trim(),f=t.slice(i+1).match(/^(\w+)(\([\s\S]*\))?$/);if(f&&!/^-?\d+$/.test(a))return{objExpr:a,attr:f[1],callPart:f[2]}}return null}tryBinaryOp(t,e,r){let s=0,i=!1,o="";for(let a=t.length-1;a>=0;a--){let c=t[a];if(i){c===o&&t[a-1]!=="\\"&&(i=!1);continue}if(c==='"'||c==="'"){i=!0,o=c;continue}if(")]}".includes(c)){s++;continue}if("([{".includes(c)){s--;continue}if(s===0){for(let f of e)if(t.slice(a,a+f.length)===f){if(f==="*"&&(t[a+1]==="*"||t[a-1]==="*"))continue;let l=t[a-1],u=t[a+f.length];if(/^[a-z]/.test(f)&&(l&&/\w/.test(l)||u&&/\w/.test(u)))continue;let g=t.slice(0,a).trim(),y=t.slice(a+f.length).trim();if(!g||!y)continue;return this.applyBinaryOp(f,g,y,r)}}}}applyBinaryOp(t,e,r,s){if(t==="and"){let a=this.pyEval(e,s);return on(a)?this.pyEval(r,s):a}if(t==="or"){let a=this.pyEval(e,s);return on(a)?a:this.pyEval(r,s)}let i=this.pyEval(e,s),o=this.pyEval(r,s);switch(t){case"+":return typeof i=="string"&&typeof o=="string"?i+o:Array.isArray(i)&&Array.isArray(o)?[...i,...o]:i+o;case"-":return i-o;case"*":if(typeof i=="string"&&typeof o=="number")return i.repeat(o);if(Array.isArray(i)&&typeof o=="number"){let a=[];for(let c=0;c<o;c++)a.push(...i);return a}return i*o;case"/":{if(o===0)throw new gt("ZeroDivisionError","division by zero");return i/o}case"//":{if(o===0)throw new gt("ZeroDivisionError","integer division or modulo by zero");return Math.floor(i/o)}case"%":{if(typeof i=="string")return this.pyStringFormat(i,Array.isArray(o)?o:[o]);if(o===0)throw new gt("ZeroDivisionError","integer division or modulo by zero");return i%o}case"**":return i**o;case"==":return kt(i)===kt(o)||i===o;case"!=":return kt(i)!==kt(o)&&i!==o;case"<":return i<o;case"<=":return i<=o;case">":return i>o;case">=":return i>=o;case"in":return this.pyIn(o,i);case"not in":return!this.pyIn(o,i);case"is":return i===o||Mn(i)&&Mn(o);case"is not":return!(i===o||Mn(i)&&Mn(o))}return V}pyIn(t,e){return typeof t=="string"?typeof e=="string"&&t.includes(e):Array.isArray(t)?t.some(r=>kt(r)===kt(e)):ht(t)?t.data.has(Ne(e)):!1}subscript(t,e,r){if(e.includes(":")){let i=e.split(":").map(c=>c.trim()),o=i[0]?this.pyEval(i[0],r):void 0,a=i[1]?this.pyEval(i[1],r):void 0;return typeof t=="string"||Array.isArray(t)?t.slice(o,a):V}let s=this.pyEval(e,r);if(Array.isArray(t)){let i=s;return i<0&&(i=t.length+i),t[i]??V}if(typeof t=="string"){let i=s;return i<0&&(i=t.length+i),t[i]??V}if(ht(t))return t.data.get(Ne(s))??V;throw new gt("TypeError",`'${fr(t)}' is not subscriptable`)}getAttr(t,e,r){return ht(t)?t.data.has(e)?t.data.get(e):e==="path"&&t.path?t.path:V:Ni(t)?t.attrs.get(e)??V:typeof t=="string"?{__class__:{__pytype__:"class",name:"str"}}[e]??V:V}callMethod(t,e,r,s){if(typeof t=="string")switch(e){case"upper":return t.toUpperCase();case"lower":return t.toLowerCase();case"strip":return(r[0]?t.replace(new RegExp(`[${r[0]}]+`,"g"),""):t).trim();case"lstrip":return t.trimStart();case"rstrip":return t.trimEnd();case"split":return t.split(typeof r[0]=="string"?r[0]:/\s+/).filter((i,o)=>o>0||i!=="");case"splitlines":return t.split(`
|
|
253
|
+
`);case"join":return vt(r[0]??[]).map(Ne).join(t);case"replace":return t.replaceAll(Ne(r[0]??""),Ne(r[1]??""));case"startswith":return t.startsWith(Ne(r[0]??""));case"endswith":return t.endsWith(Ne(r[0]??""));case"find":return t.indexOf(Ne(r[0]??""));case"index":{let i=t.indexOf(Ne(r[0]??""));if(i===-1)throw new gt("ValueError","substring not found");return i}case"count":return t.split(Ne(r[0]??"")).length-1;case"format":return this.pyStringFormat(t,r);case"encode":return t;case"decode":return t;case"isdigit":return/^\d+$/.test(t);case"isalpha":return/^[a-zA-Z]+$/.test(t);case"isalnum":return/^[a-zA-Z0-9]+$/.test(t);case"isspace":return/^\s+$/.test(t);case"isupper":return t===t.toUpperCase()&&t!==t.toLowerCase();case"islower":return t===t.toLowerCase()&&t!==t.toUpperCase();case"center":{let i=r[0]??0,o=Ne(r[1]??" ");return t.padStart(Math.floor((i+t.length)/2),o).padEnd(i,o)}case"ljust":return t.padEnd(r[0]??0,Ne(r[1]??" "));case"rjust":return t.padStart(r[0]??0,Ne(r[1]??" "));case"zfill":return t.padStart(r[0]??0,"0");case"title":return t.replace(/\b\w/g,i=>i.toUpperCase());case"capitalize":return t[0]?.toUpperCase()+t.slice(1).toLowerCase();case"swapcase":return[...t].map(i=>i===i.toUpperCase()?i.toLowerCase():i.toUpperCase()).join("")}if(Array.isArray(t))switch(e){case"append":return t.push(r[0]??V),V;case"extend":for(let i of vt(r[0]??[]))t.push(i);return V;case"insert":return t.splice(r[0]??0,0,r[1]??V),V;case"pop":{let i=r[0]!==void 0?r[0]:-1,o=i<0?t.length+i:i;return t.splice(o,1)[0]??V}case"remove":{let i=t.findIndex(o=>kt(o)===kt(r[0]??V));return i!==-1&&t.splice(i,1),V}case"index":{let i=t.findIndex(o=>kt(o)===kt(r[0]??V));if(i===-1)throw new gt("ValueError","is not in list");return i}case"count":return t.filter(i=>kt(i)===kt(r[0]??V)).length;case"sort":return t.sort((i,o)=>typeof i=="number"&&typeof o=="number"?i-o:Ne(i).localeCompare(Ne(o))),V;case"reverse":return t.reverse(),V;case"copy":return[...t];case"clear":return t.splice(0),V}if(ht(t))switch(e){case"keys":return[...t.data.keys()];case"values":return[...t.data.values()];case"items":return[...t.data.entries()].map(([i,o])=>[i,o]);case"get":return t.data.get(Ne(r[0]??""))??r[1]??V;case"update":{if(ht(r[0]??V))for(let[i,o]of r[0].data)t.data.set(i,o);return V}case"pop":{let i=Ne(r[0]??""),o=t.data.get(i)??r[1]??V;return t.data.delete(i),o}case"clear":return t.data.clear(),V;case"copy":return mt([...t.data.entries()]);case"setdefault":{let i=Ne(r[0]??"");return t.data.has(i)||t.data.set(i,r[1]??V),t.data.get(i)??V}}if(ht(t)&&t.data.has("name")&&t.data.get("name")==="posix")switch(e){case"getcwd":return this.cwd;case"getenv":return typeof r[0]=="string"?process.env[r[0]]??r[1]??V:V;case"listdir":return[];case"path":return t}if(ht(t))switch(e){case"join":return r.map(Ne).join("/").replace(/\/+/g,"/");case"exists":return!1;case"dirname":return Ne(r[0]??"").split("/").slice(0,-1).join("/")||"/";case"basename":return Ne(r[0]??"").split("/").pop()??"";case"abspath":return Ne(r[0]??"");case"splitext":{let i=Ne(r[0]??""),o=i.lastIndexOf(".");return o>0?[i.slice(0,o),i.slice(o)]:[i,""]}case"isfile":return!1;case"isdir":return!1}if(ht(t)&&t.data.has("version")&&t.data.get("version")===Hs&&e==="exit")throw new Li(r[0]??0);if(ht(t)){let i={sqrt:Math.sqrt,floor:Math.floor,ceil:Math.ceil,fabs:Math.abs,log:Math.log,log2:Math.log2,log10:Math.log10,sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:Math.asin,acos:Math.acos,atan:Math.atan,atan2:Math.atan2,pow:Math.pow,exp:Math.exp,hypot:Math.hypot};if(e in i){let o=i[e];return o(...r.map(a=>a))}if(e==="factorial"){let o=r[0]??0,a=1;for(;o>1;)a*=o--;return a}if(e==="gcd"){let o=Math.abs(r[0]??0),a=Math.abs(r[1]??0);for(;a;)[o,a]=[a,o%a];return o}}if(ht(t)){if(e==="dumps"){let i=ht(r[1]??V)?r[1]:void 0,o=i?i.data.get("indent"):void 0;return JSON.stringify(this.pyToJs(r[0]??V),null,o)}if(e==="loads")return this.jsToPy(JSON.parse(Ne(r[0]??"")))}if(Ni(t)){let i=t.attrs.get(e)??t.cls.methods.get(e)??V;if(In(i)){let o=new Map(i.closure);return o.set("self",t),i.params.slice(1).forEach((a,c)=>o.set(a,r[c]??V)),this.execBlock(i.body,o)}}throw new gt("AttributeError",`'${fr(t)}' object has no attribute '${e}'`)}pyStringFormat(t,e){let r=0;return t.replace(/%([diouxXeEfFgGcrs%])/g,(s,i)=>{if(i==="%")return"%";let o=e[r++];switch(i){case"d":case"i":return String(Math.trunc(o));case"f":return o.toFixed(6);case"s":return Ne(o??V);case"r":return kt(o??V);default:return String(o)}})}pyToJs(t){return Mn(t)?null:ht(t)?Object.fromEntries([...t.data.entries()].map(([e,r])=>[e,this.pyToJs(r)])):Array.isArray(t)?t.map(e=>this.pyToJs(e)):t}jsToPy(t){return t==null?V:typeof t=="boolean"||typeof t=="number"||typeof t=="string"?t:Array.isArray(t)?t.map(e=>this.jsToPy(e)):typeof t=="object"?mt(Object.entries(t).map(([e,r])=>[e,this.jsToPy(r)])):V}callBuiltin(t,e,r){if(r.has(t)){let s=r.get(t)??V;return In(s)?this.callFunc(s,e,r):Ja(s)?this.instantiate(s,e,r):s}switch(t){case"print":return this.output.push(e.map(Ne).join(" ")+`
|
|
254
|
+
`.replace(/\\n/g,"")),V;case"input":return this.output.push(Ne(e[0]??"")),"";case"int":{if(e.length===0)return 0;let s=e[1]??10,i=parseInt(Ne(e[0]??0),s);return Number.isNaN(i)?(()=>{throw new gt("ValueError","invalid literal for int()")})():i}case"float":{if(e.length===0)return 0;let s=parseFloat(Ne(e[0]??0));return Number.isNaN(s)?(()=>{throw new gt("ValueError","could not convert to float")})():s}case"str":return e.length===0?"":Ne(e[0]??V);case"bool":return e.length===0?!1:on(e[0]??V);case"list":return e.length===0?[]:vt(e[0]??[]);case"tuple":return e.length===0?[]:vt(e[0]??[]);case"set":return e.length===0?[]:[...new Set(vt(e[0]??[]).map(kt))].map(s=>vt(e[0]??[]).find(o=>kt(o)===s)??V);case"dict":return e.length===0?mt():ht(e[0]??V)?e[0]:mt();case"bytes":return typeof e[0]=="string"?e[0]:Ne(e[0]??"");case"bytearray":return e.length===0?"":Ne(e[0]??"");case"type":return e.length===1?`<class '${fr(e[0]??V)}'>`:V;case"isinstance":return fr(e[0]??V)===Ne(e[1]??"");case"issubclass":return!1;case"callable":return In(e[0]??V);case"hasattr":return ht(e[0]??V)?e[0].data.has(Ne(e[1]??"")):!1;case"getattr":return ht(e[0]??V)?e[0].data.get(Ne(e[1]??""))??e[2]??V:e[2]??V;case"setattr":return ht(e[0]??V)&&e[0].data.set(Ne(e[1]??""),e[2]??V),V;case"len":{let s=e[0]??V;if(typeof s=="string"||Array.isArray(s))return s.length;if(ht(s))return s.data.size;if(qr(s))return Ed(s);throw new gt("TypeError",`object of type '${fr(s)}' has no len()`)}case"range":return e.length===1?Xa(0,e[0]):e.length===2?Xa(e[0],e[1]):Xa(e[0],e[1],e[2]);case"enumerate":{let s=e[1]??0;return vt(e[0]??[]).map((i,o)=>[o+s,i])}case"zip":{let s=e.map(vt),i=Math.min(...s.map(o=>o.length));return Array.from({length:i},(o,a)=>s.map(c=>c[a]??V))}case"map":{let s=e[0]??V;return vt(e[1]??[]).map(i=>In(s)?this.callFunc(s,[i],r):V)}case"filter":{let s=e[0]??V;return vt(e[1]??[]).filter(i=>In(s)?on(this.callFunc(s,[i],r)):on(i))}case"reduce":{let s=e[0]??V,i=vt(e[1]??[]);if(i.length===0)return e[2]??V;let o=e[2]!==void 0?e[2]:i[0];for(let a of e[2]!==void 0?i:i.slice(1))o=In(s)?this.callFunc(s,[o,a],r):V;return o}case"sorted":{let s=[...vt(e[0]??[])],i=e[1]??V,o=ht(i)?i.data.get("key")??V:i;return s.sort((a,c)=>{let f=In(o)?this.callFunc(o,[a],r):a,l=In(o)?this.callFunc(o,[c],r):c;return typeof f=="number"&&typeof l=="number"?f-l:Ne(f).localeCompare(Ne(l))}),s}case"reversed":return[...vt(e[0]??[])].reverse();case"any":return vt(e[0]??[]).some(on);case"all":return vt(e[0]??[]).every(on);case"sum":return vt(e[0]??[]).reduce((s,i)=>s+i,e[1]??0);case"max":return(e.length===1?vt(e[0]??[]):e).reduce((i,o)=>i>=o?i:o);case"min":return(e.length===1?vt(e[0]??[]):e).reduce((i,o)=>i<=o?i:o);case"abs":return Math.abs(e[0]??0);case"round":return e[1]!==void 0?parseFloat(e[0].toFixed(e[1])):Math.round(e[0]??0);case"divmod":{let s=e[0],i=e[1];return[Math.floor(s/i),s%i]}case"pow":return e[0]**e[1];case"hex":return`0x${e[0].toString(16)}`;case"oct":return`0o${e[0].toString(8)}`;case"bin":return`0b${e[0].toString(2)}`;case"ord":return Ne(e[0]??"").charCodeAt(0);case"chr":return String.fromCharCode(e[0]??0);case"id":return Math.floor(Math.random()*4294967295);case"hash":return typeof e[0]=="number"?e[0]:Ne(e[0]??"").split("").reduce((s,i)=>s*31+i.charCodeAt(0)|0,0);case"open":throw new gt("PermissionError","open() not available in virtual runtime");case"repr":return kt(e[0]??V);case"iter":return e[0]??V;case"next":return Array.isArray(e[0])&&e[0].length>0?e[0].shift():e[1]??(()=>{throw new gt("StopIteration","")})();case"vars":return mt([...r.entries()].map(([s,i])=>[s,i]));case"globals":return mt([...r.entries()].map(([s,i])=>[s,i]));case"locals":return mt([...r.entries()].map(([s,i])=>[s,i]));case"dir":{if(e.length===0)return[...r.keys()];let s=e[0]??V;return typeof s=="string"?["upper","lower","strip","split","join","replace","find","format","encode","startswith","endswith","count","isdigit","isalpha","title","capitalize"]:Array.isArray(s)?["append","extend","insert","pop","remove","index","count","sort","reverse","copy","clear"]:ht(s)?["keys","values","items","get","update","pop","clear","copy","setdefault"]:[]}case"Exception":case"ValueError":case"TypeError":case"KeyError":case"IndexError":case"AttributeError":case"NameError":case"RuntimeError":case"StopIteration":case"NotImplementedError":case"OSError":case"IOError":throw new gt(t,Ne(e[0]??""));case"exec":return this.execScript(Ne(e[0]??""),r),V;case"eval":return this.pyEval(Ne(e[0]??""),r);default:throw new gt("NameError",`name '${t}' is not defined`)}}callFunc(t,e,r){let s=new Map(t.closure);t.params.forEach((i,o)=>{if(i.startsWith("*")){s.set(i.slice(1),e.slice(o));return}s.set(i,e[o]??V)});try{return this.execBlock(t.body,s)}catch(i){if(i instanceof Wr)return i.value;throw i}}instantiate(t,e,r){let s={__pytype__:"instance",cls:t,attrs:new Map};return t.methods.get("__init__")&&this.callMethod(s,"__init__",e,r),s}execScript(t,e){let r=t.split(`
|
|
255
|
+
`);this.execLines(r,0,e)}execLines(t,e,r){let s=e;for(;s<t.length;){let i=t[s];if(!i.trim()||i.trim().startsWith("#")){s++;continue}s=this.execStatement(t,s,r)}return s}execBlock(t,e){try{this.execLines(t,0,e)}catch(r){if(r instanceof Wr)return r.value;throw r}return V}getIndent(t){let e=0;for(let r of t)if(r===" ")e++;else if(r===" ")e+=4;else break;return e}collectBlock(t,e,r){let s=[];for(let i=e;i<t.length;i++){let o=t[i];if(!o.trim()){s.push("");continue}if(this.getIndent(o)<=r)break;s.push(o.slice(r+4))}return s}execStatement(t,e,r){let s=t[e],i=s.trim(),o=this.getIndent(s);if(i==="pass")return e+1;if(i==="break")throw new Pi;if(i==="continue")throw new Ti;let a=i.match(/^return(?:\s+(.+))?$/);if(a)throw new Wr(a[1]?this.pyEval(a[1],r):V);let c=i.match(/^raise(?:\s+(.+))?$/);if(c){if(c[1]){let O=this.pyEval(c[1],r);throw new gt(typeof O=="string"?O:fr(O),Ne(O))}throw new gt("RuntimeError","")}let f=i.match(/^assert\s+(.+?)(?:,\s*(.+))?$/);if(f){if(!on(this.pyEval(f[1],r)))throw new gt("AssertionError",f[2]?Ne(this.pyEval(f[2],r)):"");return e+1}let l=i.match(/^del\s+(.+)$/);if(l)return r.delete(l[1].trim()),e+1;let u=i.match(/^import\s+(\w+)(?:\s+as\s+(\w+))?$/);if(u){let[,O,x]=u,w=Ad[O];if(w){let I=w(this.cwd);this.modules.set(O,I),r.set(x??O,I)}return e+1}let h=i.match(/^from\s+(\w+)\s+import\s+(.+)$/);if(h){let[,O,x]=h,w=Ad[O];if(w){let I=w(this.cwd);if(x?.trim()==="*")for(let[U,R]of I.data)r.set(U,R);else for(let U of x.split(",").map(R=>R.trim()))r.set(U,I.data.get(U)??V)}return e+1}let g=i.match(/^def\s+(\w+)\s*\(([^)]*)\)\s*:$/);if(g){let[,O,x]=g,w=x.split(",").map(R=>R.trim()).filter(Boolean),I=this.collectBlock(t,e+1,o),U={__pytype__:"func",name:O,params:w,body:I,closure:new Map(r)};return r.set(O,U),e+1+I.length}let y=i.match(/^class\s+(\w+)(?:\(([^)]*)\))?\s*:$/);if(y){let[,O,x]=y,w=x?x.split(",").map(re=>re.trim()):[],I=this.collectBlock(t,e+1,o),U={__pytype__:"class",name:O,methods:new Map,bases:w},R=0;for(;R<I.length;){let G=I[R].trim().match(/^def\s+(\w+)\s*\(([^)]*)\)\s*:$/);if(G){let[,Y,te]=G,ce=te.split(",").map(v=>v.trim()).filter(Boolean),D=this.collectBlock(I,R+1,0);U.methods.set(Y,{__pytype__:"func",name:Y,params:ce,body:D,closure:new Map(r)}),R+=1+D.length}else R++}return r.set(O,U),e+1+I.length}if(i.startsWith("if ")&&i.endsWith(":")){let O=i.slice(3,-1).trim(),x=this.collectBlock(t,e+1,o),w=x.length+1;if(on(this.pyEval(O,r))){this.execBlock(x,new Map(r).also?.(R=>{for(let[re,G]of r)R.set(re,G)})??r),this.runBlockInScope(x,r);let U=e+1+x.length;for(;U<t.length;){let R=t[U].trim();if(this.getIndent(t[U])<o||!R.startsWith("elif")&&!R.startsWith("else"))break;let re=this.collectBlock(t,U+1,o);U+=1+re.length}return U}let I=e+1+x.length;for(;I<t.length;){let U=t[I],R=U.trim();if(this.getIndent(U)!==o)break;let re=R.match(/^elif\s+(.+):$/);if(re){let G=this.collectBlock(t,I+1,o);if(on(this.pyEval(re[1],r))){for(this.runBlockInScope(G,r),I+=1+G.length;I<t.length;){let Y=t[I].trim();if(this.getIndent(t[I])!==o||!Y.startsWith("elif")&&!Y.startsWith("else"))break;let te=this.collectBlock(t,I+1,o);I+=1+te.length}return I}I+=1+G.length;continue}if(R==="else:"){let G=this.collectBlock(t,I+1,o);return this.runBlockInScope(G,r),I+1+G.length}break}return I}let _=i.match(/^for\s+(.+?)\s+in\s+(.+?)\s*:$/);if(_){let[,O,x]=_,w=vt(this.pyEval(x.trim(),r)),I=this.collectBlock(t,e+1,o),U=[],R=e+1+I.length;R<t.length&&t[R]?.trim()==="else:"&&(U=this.collectBlock(t,R+1,o),R+=1+U.length);let re=!1;for(let G of w){if(O.includes(",")){let Y=O.split(",").map(ce=>ce.trim()),te=Array.isArray(G)?G:[G];Y.forEach((ce,D)=>r.set(ce,te[D]??V))}else r.set(O.trim(),G);try{this.runBlockInScope(I,r)}catch(Y){if(Y instanceof Pi){re=!0;break}if(Y instanceof Ti)continue;throw Y}}return!re&&U.length&&this.runBlockInScope(U,r),R}let b=i.match(/^while\s+(.+?)\s*:$/);if(b){let O=b[1],x=this.collectBlock(t,e+1,o),w=0;for(;on(this.pyEval(O,r))&&w++<1e5;)try{this.runBlockInScope(x,r)}catch(I){if(I instanceof Pi)break;if(I instanceof Ti)continue;throw I}return e+1+x.length}if(i==="try:"){let O=this.collectBlock(t,e+1,o),x=e+1+O.length,w=[],I=[],U=[];for(;x<t.length;){let re=t[x],G=re.trim();if(this.getIndent(re)!==o)break;if(G.startsWith("except")){let Y=G.match(/^except(?:\s+(\w+)(?:\s+as\s+(\w+))?)?\s*:$/),te=Y?.[1]??null,ce=Y?.[2],D=this.collectBlock(t,x+1,o);w.push({exc:te,body:D}),ce&&r.set(ce,""),x+=1+D.length}else if(G==="else:")U=this.collectBlock(t,x+1,o),x+=1+U.length;else if(G==="finally:")I=this.collectBlock(t,x+1,o),x+=1+I.length;else break}let R=null;try{this.runBlockInScope(O,r),U.length&&this.runBlockInScope(U,r)}catch(re){if(re instanceof gt){R=re;let G=!1;for(let Y of w)if(Y.exc===null||Y.exc===re.type||Y.exc==="Exception"){this.runBlockInScope(Y.body,r),G=!0;break}if(!G)throw re}else throw re}finally{I.length&&this.runBlockInScope(I,r)}return x}let C=i.match(/^with\s+(.+?)\s+as\s+(\w+)\s*:$/);if(C){let O=this.collectBlock(t,e+1,o);return r.set(C[2],V),this.runBlockInScope(O,r),e+1+O.length}let L=i.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*(\+=|-=|\*=|\/\/=|\/=|%=|\*\*=|&=|\|=)\s*(.+)$/);if(L){let[,O,x,w]=L,I=r.get(O)??0,U=this.pyEval(w,r),R;switch(x){case"+=":R=typeof I=="string"?I+Ne(U):I+U;break;case"-=":R=I-U;break;case"*=":R=I*U;break;case"/=":R=I/U;break;case"//=":R=Math.floor(I/U);break;case"%=":R=I%U;break;case"**=":R=I**U;break;default:R=U}return r.set(O,R),e+1}let F=i.match(/^([A-Za-z_][A-Za-z0-9_]*)\[(.+)\]\s*=\s*(.+)$/);if(F){let[,O,x,w]=F,I=r.get(O)??V,U=this.pyEval(w,r)??V,R=this.pyEval(x,r)??V;return Array.isArray(I)?I[R]=U:ht(I)&&I.data.set(Ne(R),U),e+1}let k=i.match(/^([A-Za-z_][A-Za-z0-9_.]+)\s*=\s*(.+)$/);if(k){let O=k[1].lastIndexOf(".");if(O!==-1){let x=k[1].slice(0,O),w=k[1].slice(O+1),I=this.pyEval(k[2],r),U=this.pyEval(x,r);return ht(U)?U.data.set(w,I):Ni(U)&&U.attrs.set(w,I),e+1}}let K=i.match(/^([A-Za-z_][A-Za-z0-9_,\s]*),\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.+)$/);if(K){let O=this.pyEval(K[3],r),x=i.split("=")[0].split(",").map(I=>I.trim()),w=vt(O);return x.forEach((I,U)=>r.set(I,w[U]??V)),e+1}let ee=i.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*(?::[^=]+)?\s*=\s*(.+)$/);if(ee){let[,O,x]=ee;return r.set(O,this.pyEval(x,r)),e+1}try{this.pyEval(i,r)}catch(O){if(O instanceof gt||O instanceof Li)throw O}return e+1}runBlockInScope(t,e){this.execLines(t,0,e)}run(t){let e=_A(this.cwd);try{this.execScript(t,e)}catch(r){return r instanceof Li?{stdout:this.getOutput(),stderr:this.getStderr(),exitCode:r.code}:r instanceof gt?(this.stderr.push(r.toString()),{stdout:this.getOutput(),stderr:this.getStderr(),exitCode:1}):r instanceof Wr?{stdout:this.getOutput(),stderr:this.getStderr(),exitCode:0}:(this.stderr.push(`RuntimeError: ${r}`),{stdout:this.getOutput(),stderr:this.getStderr(),exitCode:1})}return{stdout:this.getOutput(),stderr:this.getStderr(),exitCode:0}}},_d={name:"python3",aliases:["python"],description:"Python 3 interpreter (virtual)",category:"system",params:["[--version] [-c <code>] [-V] [file]"],run:({args:n,shell:t,cwd:e})=>{if(!t.packageManager.isInstalled("python3"))return{stderr:`bash: python3: command not found
|
|
256
256
|
Hint: install it with: apt install python3
|
|
257
|
-
`,exitCode:127};if(ne(n,["--version","-V"]))return{stdout:`${
|
|
258
|
-
`,exitCode:0};if(ne(n,["--version-full"]))return{stdout:`${
|
|
257
|
+
`,exitCode:127};if(ne(n,["--version","-V"]))return{stdout:`${AA}
|
|
258
|
+
`,exitCode:0};if(ne(n,["--version-full"]))return{stdout:`${Hs}
|
|
259
259
|
`,exitCode:0};let r=n.indexOf("-c");if(r!==-1){let i=n[r+1];if(!i)return{stderr:`python3: -c requires a code argument
|
|
260
260
|
`,exitCode:1};let o=i.replace(/\\n/g,`
|
|
261
|
-
`).replace(/\\t/g," "),a=new
|
|
262
|
-
`,exitCode:2};let o=t.vfs.readFile(i),a=new
|
|
261
|
+
`).replace(/\\t/g," "),a=new Qs(e),{stdout:c,stderr:f,exitCode:l}=a.run(o);return{stdout:c||void 0,stderr:f||void 0,exitCode:l}}let s=n.find(i=>!i.startsWith("-"));if(s){let i=le(e,s);if(!t.vfs.exists(i))return{stderr:`python3: can't open file '${s}': [Errno 2] No such file or directory
|
|
262
|
+
`,exitCode:2};let o=t.vfs.readFile(i),a=new Qs(e),{stdout:c,stderr:f,exitCode:l}=a.run(o);return{stdout:c||void 0,stderr:f||void 0,exitCode:l}}return{stdout:`${Hs}
|
|
263
263
|
Type "help", "copyright", "credits" or "license" for more information.
|
|
264
|
-
>>> `,exitCode:0}}};var
|
|
264
|
+
>>> `,exitCode:0}}};var yd={name:"read",description:"Read a line from stdin into variables",category:"shell",params:["[-r] [-p prompt] <var...>"],run:({args:n,stdin:t,env:e})=>{let r=n.indexOf("-p"),s=n.filter((a,c)=>a!=="-r"&&a!=="-p"&&n[c-1]!=="-p"),i=(t??"").split(`
|
|
265
265
|
`)[0]??"",o=ne(n,["-r"])?i:i.replace(/\\(?:\r?\n|.)/g,a=>a[1]===`
|
|
266
|
-
`||a[1]==="\r"?"":a[1]);if(!e)return{exitCode:0};if(s.length===0)e.vars.REPLY=o;else if(s.length===1)e.vars[s[0]]=o;else{let a=o.split(/\s+/);for(let c=0;c<s.length;c++)e.vars[s[c]]=c<s.length-1?a[c]??"":a.slice(c).join(" ")}return{exitCode:0}}};var Vf={name:"rm",description:"Remove files or directories",category:"files",params:["[-r|-rf] <path>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{if(r.length===0)return{stderr:"rm: missing operand",exitCode:1};let s=ne(r,["-r","-rf","-fr"]),i=[];for(let o=0;;o+=1){let a=dn(r,o,{flags:["-r","-rf","-fr"]});if(!a)break;i.push(a)}if(i.length===0)return{stderr:"rm: missing operand",exitCode:1};for(let o of i){let a=le(e,o);$e(n,a,"rm"),t.vfs.remove(a,{recursive:s})}return{exitCode:0}}};var Gf={name:"sed",description:"Stream editor for filtering and transforming text",category:"text",params:["-e <expr> [file]","s/pattern/replace/[g]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:s})=>{let i=ne(r,["-i"]),o=jt(r,["-e"])??r.find(b=>!b.startsWith("-")),a=r.filter(b=>!b.startsWith("-")&&b!==o).pop();if(!o)return{stderr:"sed: no expression",exitCode:1};let c=s??"";if(a){let b=le(e,a);try{c=t.vfs.readFile(b)}catch{return{stderr:`sed: ${a}: No such file or directory`,exitCode:1}}}let f=o.match(/^s([^a-zA-Z0-9])(.+?)\1(.*?)\1([gi]*)$/);if(!f)return{stderr:`sed: unrecognized command: ${o}`,exitCode:1};let[,,l,u,h]=f,g=(h??"").includes("i")?"gi":(h??"").includes("g")?"g":"",y;try{y=new RegExp(l,g||"")}catch{return{stderr:`sed: invalid regex: ${l}`,exitCode:1}}let _=((h??"").includes("g")||g.includes("g"),c.replace(y,u??""));if(i&&a){let b=le(e,a);return t.writeFileAsUser(n,b,_),{exitCode:0}}return{stdout:_,exitCode:0}}};async function Yf(n,t,e,r,s,i,o){let a={exitCode:0},c=0;for(;c<n.length;){let f=n[c];if(a=await Pp(f.pipeline,t,e,r,s,i,o),o.lastExitCode=a.exitCode??0,a.closeSession||a.switchUser)return a;let l=f.op;if(!(!l||l===";")){if(l==="&&"){if((a.exitCode??0)!==0)for(;c<n.length&&n[c]?.op==="&&";)c++}else if(l==="||"&&(a.exitCode??0)===0)for(;c<n.length&&n[c]?.op==="||";)c++}c++}return a}async function Pp(n,t,e,r,s,i,o){if(!n.isValid)return{stderr:n.error||"Syntax error",exitCode:1};if(n.commands.length===0)return{exitCode:0};let a=o??{vars:{},lastExitCode:0};return n.commands.length===1?Tp(n.commands[0],t,e,r,s,i,a):Lp(n.commands,t,e,r,s,i,a)}async function Tp(n,t,e,r,s,i,o){let a;if(n.inputFile){let f=le(s,n.inputFile);try{a=i.vfs.readFile(f)}catch{return{stderr:`${n.inputFile}: No such file or directory`,exitCode:1}}}let c=await zi(n.name,n.args,t,e,r,s,i,a,o);if(n.outputFile){let f=le(s,n.outputFile),l=c.stdout||"";try{if(n.appendOutput){let u=(()=>{try{return i.vfs.readFile(f)}catch{return""}})();i.writeFileAsUser(t,f,u+l)}else i.writeFileAsUser(t,f,l);return{...c,stdout:""}}catch{return{...c,stderr:`Failed to write to ${n.outputFile}`,exitCode:1}}}return c}async function Lp(n,t,e,r,s,i,o){let a="",c=0;for(let f=0;f<n.length;f++){let l=n[f];if(f===0&&l.inputFile){let h=le(s,l.inputFile);try{a=i.vfs.readFile(h)}catch{return{stderr:`${l.inputFile}: No such file or directory`,exitCode:1}}}let u=await zi(l.name,l.args,t,e,r,s,i,a,o);if(c=u.exitCode??0,f===n.length-1&&l.outputFile){let h=le(s,l.outputFile),g=u.stdout||"";try{if(l.appendOutput){let y=(()=>{try{return i.vfs.readFile(h)}catch{return""}})();i.writeFileAsUser(t,h,y+g)}else i.writeFileAsUser(t,h,g);a=""}catch{return{stderr:`Failed to write to ${l.outputFile}`,exitCode:1}}}else a=u.stdout||"";if(u.stderr&&c!==0)return{stderr:u.stderr,exitCode:c};if(u.closeSession||u.switchUser)return u}return{stdout:a,exitCode:c}}function zf(n){let t=n.trim();if(!t)return{statements:[],isValid:!0};try{return{statements:Up(t),isValid:!0}}catch(e){return{statements:[],isValid:!1,error:e.message}}}function Up(n){let t=Dp(n),e=[];for(let r of t){let i={pipeline:{commands:Op(r.text.trim()),isValid:!0}};r.op&&(i.op=r.op),e.push(i)}return e}function Dp(n){let t=[],e="",r=0,s=!1,i="",o=0,a=c=>{e.trim()&&t.push({text:e,op:c}),e=""};for(;o<n.length;){let c=n[o],f=n.slice(o,o+2);if((c==='"'||c==="'")&&!s){s=!0,i=c,e+=c,o++;continue}if(s&&c===i){s=!1,e+=c,o++;continue}if(s){e+=c,o++;continue}if(c==="("){r++,e+=c,o++;continue}if(c===")"){r--,e+=c,o++;continue}if(r>0){e+=c,o++;continue}if(f==="&&"){a("&&"),o+=2;continue}if(f==="||"){a("||"),o+=2;continue}if(c===";"){a(";"),o++;continue}e+=c,o++}return a(),t}function Op(n){return Mp(n).map($p)}function Mp(n){let t=[],e="",r=!1,s="";for(let o=0;o<n.length;o++){let a=n[o];if((a==='"'||a==="'")&&!r){r=!0,s=a,e+=a;continue}if(r&&a===s){r=!1,e+=a;continue}if(r){e+=a;continue}if(a==="|"&&n[o+1]!=="|"){if(!e.trim())throw new Error("Syntax error near unexpected token '|'");t.push(e.trim()),e=""}else e+=a}let i=e.trim();if(!i&&t.length>0)throw new Error("Syntax error near unexpected token '|'");return i&&t.push(i),t}function $p(n){let t=Fp(n);if(t.length===0)return{name:"",args:[]};let e=[],r,s,i=!1,o=0;for(;o<t.length;){let c=t[o];if(c==="<"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after <");r=t[o],o++}else if(c===">>"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after >>");s=t[o],i=!0,o++}else if(c===">"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after >");s=t[o],i=!1,o++}else e.push(c),o++}return{name:(e[0]??"").toLowerCase(),args:e.slice(1),inputFile:r,outputFile:s,appendOutput:i}}function Fp(n){let t=[],e="",r=!1,s="",i=0;for(;i<n.length;){let o=n[i],a=n[i+1];if((o==='"'||o==="'")&&!r){r=!0,s=o,i++;continue}if(r&&o===s){r=!1,s="",i++;continue}if(r){e+=o,i++;continue}if(o===" "){e&&(t.push(e),e=""),i++;continue}if((o===">"||o==="<")&&!r){e&&(t.push(e),e=""),o===">"&&a===">"?(t.push(">>"),i+=2):(t.push(o),i++);continue}e+=o,i++}return e&&t.push(e),t}function jf(n){let t=[],e="",r=!1,s="",i=0;for(;i<n.length;){let o=n[i],a=n[i+1];if((o==='"'||o==="'")&&!r){r=!0,s=o,i++;continue}if(r&&o===s){r=!1,s="",i++;continue}if(r){e+=o,i++;continue}if(o===" "){e&&(t.push(e),e=""),i++;continue}if((o===">"||o==="<")&&!r){e&&(t.push(e),e=""),o===">"&&a===">"?(t.push(">>"),i+=2):(t.push(o),i++);continue}e+=o,i++}return e&&t.push(e),t}function Ir(n,t){return{vars:{PATH:"/usr/local/bin:/usr/bin:/bin",HOME:`/home/${n}`,USER:n,LOGNAME:n,SHELL:"/bin/sh",TERM:"xterm-256color",HOSTNAME:t,PS1:"\\u@\\h:\\w\\$ "},lastExitCode:0}}function Xf(n,t,e,r){if(n.startsWith("/")){if(!e.vfs.exists(n))return null;try{let i=e.vfs.stat(n);return i.type!=="file"||!(i.mode&73)||(n.startsWith("/sbin/")||n.startsWith("/usr/sbin/"))&&r!=="root"?null:n}catch{return null}}let s=(t.vars.PATH??"/usr/local/bin:/usr/bin:/bin").split(":");for(let i of s){if((i==="/sbin"||i==="/usr/sbin")&&r!=="root")continue;let o=`${i}/${n}`;if(e.vfs.exists(o))try{let a=e.vfs.stat(o);if(a.type!=="file"||!(a.mode&73))continue;return o}catch{}}return null}async function zi(n,t,e,r,s,i,o,a,c){let f=c.vars[`__alias_${n}`];if(f)return Bt(`${f} ${t.join(" ")}`,e,r,s,i,o,a,c);let l=Sn(n);if(!l){let u=Xf(n,c,o,e);if(u){let h=o.vfs.readFile(u),g=h.match(/exec\s+builtin\s+(\S+)/);if(g){let _=Sn(g[1]);if(_)return await _.run({authUser:e,hostname:r,activeSessions:o.users.listActiveSessions(),rawInput:[n,...t].join(" "),mode:s,args:t,stdin:a,cwd:i,shell:o,env:c})}let y=Sn("sh");if(y)return await y.run({authUser:e,hostname:r,activeSessions:o.users.listActiveSessions(),rawInput:`sh -c ${JSON.stringify(h)}`,mode:s,args:["-c",h,"--",...t],stdin:a,cwd:i,shell:o,env:c})}return{stderr:`${n}: command not found`,exitCode:127}}try{return await l.run({authUser:e,hostname:r,activeSessions:o.users.listActiveSessions(),rawInput:[n,...t].join(" "),mode:s,args:t,stdin:a,cwd:i,shell:o,env:c})}catch(u){return{stderr:u instanceof Error?u.message:"Command failed",exitCode:1}}}async function Bt(n,t,e,r,s,i,o,a){let c=n.trim();if(c.length===0)return{exitCode:0};let f=a??Ir(t,e),u=jf(c)[0]?.toLowerCase()??"",h=f.vars[`__alias_${u}`],g=h?c.replace(u,h):c;if(/(?<![|&])[|](?![|])/.test(g)||g.includes(">")||g.includes("<")||g.includes("&&")||g.includes("||")||g.includes(";")){let k=zf(g);if(!k.isValid)return{stderr:k.error||"Syntax error",exitCode:1};try{return await Yf(k.statements,t,e,r,s,i,f)}catch(K){return{stderr:K instanceof Error?K.message:"Execution failed",exitCode:1}}}let _=await Hi(g,f.vars,f.lastExitCode,k=>Bt(k,t,e,r,s,i,void 0,f).then(K=>K.stdout??"")),b=jf(_.trim()),C=b[0]?.toLowerCase()??"",L=b.slice(1),F=Sn(C);if(!F){let k=Xf(C,f,i,t);if(k){let K=i.vfs.readFile(k),ee=K.match(/exec\s+builtin\s+(\S+)/);if(ee){let x=ee[1],w=Sn(x);if(w)return await w.run({authUser:t,hostname:e,activeSessions:i.users.listActiveSessions(),rawInput:[C,...L].join(" "),mode:r,args:L,stdin:o,cwd:s,shell:i,env:f})}let O=Sn("sh");if(O)return await O.run({authUser:t,hostname:e,activeSessions:i.users.listActiveSessions(),rawInput:`sh -c ${JSON.stringify(K)}`,mode:r,args:["-c",K,"--",...L],stdin:o,cwd:s,shell:i,env:f})}return{stderr:`${C}: command not found`,exitCode:127}}try{return await F.run({authUser:t,hostname:e,activeSessions:i.users.listActiveSessions(),rawInput:_,mode:r,args:L,stdin:o,cwd:s,shell:i,env:f})}catch(k){return{stderr:k instanceof Error?k.message:"Command failed",exitCode:1}}}async function ho(n,t,e,r){return Hi(n,t,e,s=>Bt(s,r.authUser,r.hostname,r.mode,r.cwd,r.shell,void 0,r.env).then(i=>i.stdout??""))}function ir(n){let t=[],e=0;for(;e<n.length;){let r=n[e].trim();if(!r||r.startsWith("#")){e++;continue}if(r.startsWith("if ")||r==="if"){let s=r.replace(/^if\s+/,"").replace(/;\s*then\s*$/,"").trim(),i=[],o=[],a=[],c="then",f="";for(e++;e<n.length&&n[e]?.trim()!=="fi";){let l=n[e].trim();l.startsWith("elif ")?(c="elif",f=l.replace(/^elif\s+/,"").replace(/;\s*then\s*$/,"").trim(),o.push({cond:f,body:[]})):l==="else"?c="else":l!=="then"&&(c==="then"?i.push(l):c==="elif"&&o.length>0?o[o.length-1].body.push(l):a.push(l)),e++}t.push({type:"if",cond:s,then_:i,elif:o,else_:a})}else if(r.startsWith("for ")){let s=r.match(/^for\s+(\w+)\s+in\s+(.+?)(?:\s*;\s*do)?$/);if(s){let i=[];for(e++;e<n.length&&n[e]?.trim()!=="done";){let o=n[e].trim().replace(/^do\s+/,"");o&&o!=="do"&&i.push(o),e++}t.push({type:"for",var:s[1],list:s[2],body:i})}else t.push({type:"cmd",line:r})}else if(r.startsWith("while ")){let s=r.replace(/^while\s+/,"").replace(/;\s*do\s*$/,"").trim(),i=[];for(e++;e<n.length&&n[e]?.trim()!=="done";){let o=n[e].trim().replace(/^do\s+/,"");o&&o!=="do"&&i.push(o),e++}t.push({type:"while",cond:s,body:i})}else t.push({type:"cmd",line:r});e++}return t}async function uo(n,t){let e=await ho(n,t.env.vars,t.env.lastExitCode,t),r=e.match(/^\[?\s*(.+?)\s*\]?$/);if(r){let i=r[1],o=i.match(/^-([fdeznr])\s+(.+)$/);if(o){let[,f,l]=o,u=le(t.cwd,l);if(f==="f")return t.shell.vfs.exists(u)&&t.shell.vfs.stat(u).type==="file";if(f==="d")return t.shell.vfs.exists(u)&&t.shell.vfs.stat(u).type==="directory";if(f==="e")return t.shell.vfs.exists(u);if(f==="z")return(l??"").length===0;if(f==="n")return(l??"").length>0}let a=i.match(/^"?([^"]*)"?\s*(==|!=|=|<|>)\s*"?([^"]*)"?$/);if(a){let[,f,l,u]=a;if(l==="=="||l==="=")return f===u;if(l==="!=")return f!==u}let c=i.match(/^(\S+)\s+(-eq|-ne|-lt|-le|-gt|-ge)\s+(\S+)$/);if(c){let[,f,l,u]=c,h=Number(f),g=Number(u);if(l==="-eq")return h===g;if(l==="-ne")return h!==g;if(l==="-lt")return h<g;if(l==="-le")return h<=g;if(l==="-gt")return h>g;if(l==="-ge")return h>=g}}return((await Bt(e,t.authUser,t.hostname,t.mode,t.cwd,t.shell,void 0,t.env)).exitCode??0)===0}async function sr(n,t){let e={exitCode:0},r="";for(let s of n)if(s.type==="cmd"){let i=await ho(s.line,t.env.vars,t.env.lastExitCode,t),o=/^([A-Za-z_][A-Za-z0-9_]*)=(.*)/,a=i.trim().split(/\s+/);if(a.length>0&&o.test(a[0])&&a.every(l=>o.test(l))){for(let l of a){let u=l.match(o);t.env.vars[u[1]]=u[2]}t.env.lastExitCode=0;continue}let c=await Bt(i,t.authUser,t.hostname,t.mode,t.cwd,t.shell,void 0,t.env);if(t.env.lastExitCode=c.exitCode??0,c.stdout&&(r+=`${c.stdout}
|
|
267
|
-
`),c.stderr)return{...c,stdout:r.trim()};e=c}else if(s.type==="if"){let i=!1;if(await
|
|
268
|
-
`),i=!0}else{for(let o of s.elif)if(await
|
|
269
|
-
`),i=!0;break}if(!i&&s.else_.length>0){let o=await
|
|
270
|
-
`)}}}else if(s.type==="for"){let o=(await
|
|
271
|
-
`),c.closeSession)return c}}else if(s.type==="while"){let i=0;for(;i<1e3&&await
|
|
272
|
-
`),o.closeSession)return o;i++}}return{...e,stdout:r.trim()||e.stdout}}var
|
|
273
|
-
`).map(f=>f.trim()).filter(f=>f&&!f.startsWith("#")),c=
|
|
266
|
+
`||a[1]==="\r"?"":a[1]);if(!e)return{exitCode:0};if(s.length===0)e.vars.REPLY=o;else if(s.length===1)e.vars[s[0]]=o;else{let a=o.split(/\s+/);for(let c=0;c<s.length;c++)e.vars[s[c]]=c<s.length-1?a[c]??"":a.slice(c).join(" ")}return{exitCode:0}}};var bd={name:"rm",description:"Remove files or directories",category:"files",params:["[-r|-rf] <path>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{if(r.length===0)return{stderr:"rm: missing operand",exitCode:1};let s=ne(r,["-r","-rf","-fr"]),i=[];for(let o=0;;o+=1){let a=mn(r,o,{flags:["-r","-rf","-fr"]});if(!a)break;i.push(a)}if(i.length===0)return{stderr:"rm: missing operand",exitCode:1};for(let o of i){let a=le(e,o);$e(n,a,"rm"),t.vfs.remove(a,{recursive:s})}return{exitCode:0}}};var xd={name:"sed",description:"Stream editor for filtering and transforming text",category:"text",params:["-e <expr> [file]","s/pattern/replace/[g]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:s})=>{let i=ne(r,["-i"]),o=en(r,["-e"])??r.find(b=>!b.startsWith("-")),a=r.filter(b=>!b.startsWith("-")&&b!==o).pop();if(!o)return{stderr:"sed: no expression",exitCode:1};let c=s??"";if(a){let b=le(e,a);try{c=t.vfs.readFile(b)}catch{return{stderr:`sed: ${a}: No such file or directory`,exitCode:1}}}let f=o.match(/^s([^a-zA-Z0-9])(.+?)\1(.*?)\1([gi]*)$/);if(!f)return{stderr:`sed: unrecognized command: ${o}`,exitCode:1};let[,,l,u,h]=f,g=(h??"").includes("i")?"gi":(h??"").includes("g")?"g":"",y;try{y=new RegExp(l,g||"")}catch{return{stderr:`sed: invalid regex: ${l}`,exitCode:1}}let _=((h??"").includes("g")||g.includes("g"),c.replace(y,u??""));if(i&&a){let b=le(e,a);return t.writeFileAsUser(n,b,_),{exitCode:0}}return{stdout:_,exitCode:0}}};async function Sd(n,t,e,r,s,i,o){let a={exitCode:0},c=0;for(;c<n.length;){let f=n[c];if(a=await IA(f.pipeline,t,e,r,s,i,o),o.lastExitCode=a.exitCode??0,a.closeSession||a.switchUser)return a;let l=f.op;if(!(!l||l===";")){if(l==="&&"){if((a.exitCode??0)!==0)for(;c<n.length&&n[c]?.op==="&&";)c++}else if(l==="||"&&(a.exitCode??0)===0)for(;c<n.length&&n[c]?.op==="||";)c++}c++}return a}async function IA(n,t,e,r,s,i,o){if(!n.isValid)return{stderr:n.error||"Syntax error",exitCode:1};if(n.commands.length===0)return{exitCode:0};let a=o??{vars:{},lastExitCode:0};return n.commands.length===1?CA(n.commands[0],t,e,r,s,i,a):vA(n.commands,t,e,r,s,i,a)}async function CA(n,t,e,r,s,i,o){let a;if(n.inputFile){let f=le(s,n.inputFile);try{a=i.vfs.readFile(f)}catch{return{stderr:`${n.inputFile}: No such file or directory`,exitCode:1}}}let c=await Ws(n.name,n.args,t,e,r,s,i,a,o);if(n.outputFile){let f=le(s,n.outputFile),l=c.stdout||"";try{if(n.appendOutput){let u=(()=>{try{return i.vfs.readFile(f)}catch{return""}})();i.writeFileAsUser(t,f,u+l)}else i.writeFileAsUser(t,f,l);return{...c,stdout:""}}catch{return{...c,stderr:`Failed to write to ${n.outputFile}`,exitCode:1}}}return c}async function vA(n,t,e,r,s,i,o){let a="",c=0;for(let f=0;f<n.length;f++){let l=n[f];if(f===0&&l.inputFile){let h=le(s,l.inputFile);try{a=i.vfs.readFile(h)}catch{return{stderr:`${l.inputFile}: No such file or directory`,exitCode:1}}}let u=await Ws(l.name,l.args,t,e,r,s,i,a,o);if(c=u.exitCode??0,f===n.length-1&&l.outputFile){let h=le(s,l.outputFile),g=u.stdout||"";try{if(l.appendOutput){let y=(()=>{try{return i.vfs.readFile(h)}catch{return""}})();i.writeFileAsUser(t,h,y+g)}else i.writeFileAsUser(t,h,g);a=""}catch{return{stderr:`Failed to write to ${l.outputFile}`,exitCode:1}}}else a=u.stdout||"";if(u.stderr&&c!==0)return{stderr:u.stderr,exitCode:c};if(u.closeSession||u.switchUser)return u}return{stdout:a,exitCode:c}}function wd(n){let t=n.trim();if(!t)return{statements:[],isValid:!0};try{return{statements:kA(t),isValid:!0}}catch(e){return{statements:[],isValid:!1,error:e.message}}}function kA(n){let t=BA(n),e=[];for(let r of t){let i={pipeline:{commands:RA(r.text.trim()),isValid:!0}};r.op&&(i.op=r.op),e.push(i)}return e}function BA(n){let t=[],e="",r=0,s=!1,i="",o=0,a=c=>{e.trim()&&t.push({text:e,op:c}),e=""};for(;o<n.length;){let c=n[o],f=n.slice(o,o+2);if((c==='"'||c==="'")&&!s){s=!0,i=c,e+=c,o++;continue}if(s&&c===i){s=!1,e+=c,o++;continue}if(s){e+=c,o++;continue}if(c==="("){r++,e+=c,o++;continue}if(c===")"){r--,e+=c,o++;continue}if(r>0){e+=c,o++;continue}if(f==="&&"){a("&&"),o+=2;continue}if(f==="||"){a("||"),o+=2;continue}if(c===";"){a(";"),o++;continue}e+=c,o++}return a(),t}function RA(n){return NA(n).map(PA)}function NA(n){let t=[],e="",r=!1,s="";for(let o=0;o<n.length;o++){let a=n[o];if((a==='"'||a==="'")&&!r){r=!0,s=a,e+=a;continue}if(r&&a===s){r=!1,e+=a;continue}if(r){e+=a;continue}if(a==="|"&&n[o+1]!=="|"){if(!e.trim())throw new Error("Syntax error near unexpected token '|'");t.push(e.trim()),e=""}else e+=a}let i=e.trim();if(!i&&t.length>0)throw new Error("Syntax error near unexpected token '|'");return i&&t.push(i),t}function PA(n){let t=TA(n);if(t.length===0)return{name:"",args:[]};let e=[],r,s,i=!1,o=0;for(;o<t.length;){let c=t[o];if(c==="<"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after <");r=t[o],o++}else if(c===">>"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after >>");s=t[o],i=!0,o++}else if(c===">"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after >");s=t[o],i=!1,o++}else e.push(c),o++}return{name:(e[0]??"").toLowerCase(),args:e.slice(1),inputFile:r,outputFile:s,appendOutput:i}}function TA(n){let t=[],e="",r=!1,s="",i=0;for(;i<n.length;){let o=n[i],a=n[i+1];if((o==='"'||o==="'")&&!r){r=!0,s=o,i++;continue}if(r&&o===s){r=!1,s="",i++;continue}if(r){e+=o,i++;continue}if(o===" "){e&&(t.push(e),e=""),i++;continue}if((o===">"||o==="<")&&!r){e&&(t.push(e),e=""),o===">"&&a===">"?(t.push(">>"),i+=2):(t.push(o),i++);continue}e+=o,i++}return e&&t.push(e),t}function Id(n){let t=[],e="",r=!1,s="",i=0;for(;i<n.length;){let o=n[i],a=n[i+1];if((o==='"'||o==="'")&&!r){r=!0,s=o,i++;continue}if(r&&o===s){r=!1,s="",i++;continue}if(r){e+=o,i++;continue}if(o===" "){e&&(t.push(e),e=""),i++;continue}if((o===">"||o==="<")&&!r){e&&(t.push(e),e=""),o===">"&&a===">"?(t.push(">>"),i+=2):(t.push(o),i++);continue}e+=o,i++}return e&&t.push(e),t}function Kr(n,t){return{vars:{PATH:"/usr/local/bin:/usr/bin:/bin",HOME:`/home/${n}`,USER:n,LOGNAME:n,SHELL:"/bin/sh",TERM:"xterm-256color",HOSTNAME:t,PS1:"\\u@\\h:\\w\\$ "},lastExitCode:0}}function Cd(n,t,e,r){if(n.startsWith("/")){if(!e.vfs.exists(n))return null;try{let i=e.vfs.stat(n);return i.type!=="file"||!(i.mode&73)||(n.startsWith("/sbin/")||n.startsWith("/usr/sbin/"))&&r!=="root"?null:n}catch{return null}}let s=(t.vars.PATH??"/usr/local/bin:/usr/bin:/bin").split(":");for(let i of s){if((i==="/sbin"||i==="/usr/sbin")&&r!=="root")continue;let o=`${i}/${n}`;if(e.vfs.exists(o))try{let a=e.vfs.stat(o);if(a.type!=="file"||!(a.mode&73))continue;return o}catch{}}return null}async function Ws(n,t,e,r,s,i,o,a,c){let f=c.vars[`__alias_${n}`];if(f)return Bt(`${f} ${t.join(" ")}`,e,r,s,i,o,a,c);let l=Cn(n);if(!l){let u=Cd(n,c,o,e);if(u){let h=o.vfs.readFile(u),g=h.match(/exec\s+builtin\s+(\S+)/);if(g){let _=Cn(g[1]);if(_)return await _.run({authUser:e,hostname:r,activeSessions:o.users.listActiveSessions(),rawInput:[n,...t].join(" "),mode:s,args:t,stdin:a,cwd:i,shell:o,env:c})}let y=Cn("sh");if(y)return await y.run({authUser:e,hostname:r,activeSessions:o.users.listActiveSessions(),rawInput:`sh -c ${JSON.stringify(h)}`,mode:s,args:["-c",h,"--",...t],stdin:a,cwd:i,shell:o,env:c})}return{stderr:`${n}: command not found`,exitCode:127}}try{return await l.run({authUser:e,hostname:r,activeSessions:o.users.listActiveSessions(),rawInput:[n,...t].join(" "),mode:s,args:t,stdin:a,cwd:i,shell:o,env:c})}catch(u){return{stderr:u instanceof Error?u.message:"Command failed",exitCode:1}}}async function Bt(n,t,e,r,s,i,o,a){let c=n.trim();if(c.length===0)return{exitCode:0};let f=a??Kr(t,e),u=Id(c)[0]?.toLowerCase()??"",h=f.vars[`__alias_${u}`],g=h?c.replace(u,h):c;if(/(?<![|&])[|](?![|])/.test(g)||g.includes(">")||g.includes("<")||g.includes("&&")||g.includes("||")||g.includes(";")){let k=wd(g);if(!k.isValid)return{stderr:k.error||"Syntax error",exitCode:1};try{return await Sd(k.statements,t,e,r,s,i,f)}catch(K){return{stderr:K instanceof Error?K.message:"Execution failed",exitCode:1}}}let _=await Us(g,f.vars,f.lastExitCode,k=>Bt(k,t,e,r,s,i,void 0,f).then(K=>K.stdout??"")),b=Id(_.trim()),C=b[0]?.toLowerCase()??"",L=b.slice(1),F=Cn(C);if(!F){let k=Cd(C,f,i,t);if(k){let K=i.vfs.readFile(k),ee=K.match(/exec\s+builtin\s+(\S+)/);if(ee){let x=ee[1],w=Cn(x);if(w)return await w.run({authUser:t,hostname:e,activeSessions:i.users.listActiveSessions(),rawInput:[C,...L].join(" "),mode:r,args:L,stdin:o,cwd:s,shell:i,env:f})}let O=Cn("sh");if(O)return await O.run({authUser:t,hostname:e,activeSessions:i.users.listActiveSessions(),rawInput:`sh -c ${JSON.stringify(K)}`,mode:r,args:["-c",K,"--",...L],stdin:o,cwd:s,shell:i,env:f})}return{stderr:`${C}: command not found`,exitCode:127}}try{return await F.run({authUser:t,hostname:e,activeSessions:i.users.listActiveSessions(),rawInput:_,mode:r,args:L,stdin:o,cwd:s,shell:i,env:f})}catch(k){return{stderr:k instanceof Error?k.message:"Command failed",exitCode:1}}}async function rc(n,t,e,r){return Us(n,t,e,s=>Bt(s,r.authUser,r.hostname,r.mode,r.cwd,r.shell,void 0,r.env).then(i=>i.stdout??""))}function lr(n){let t=[],e=0;for(;e<n.length;){let r=n[e].trim();if(!r||r.startsWith("#")){e++;continue}if(r.startsWith("if ")||r==="if"){let s=r.replace(/^if\s+/,"").replace(/;\s*then\s*$/,"").trim(),i=[],o=[],a=[],c="then",f="";for(e++;e<n.length&&n[e]?.trim()!=="fi";){let l=n[e].trim();l.startsWith("elif ")?(c="elif",f=l.replace(/^elif\s+/,"").replace(/;\s*then\s*$/,"").trim(),o.push({cond:f,body:[]})):l==="else"?c="else":l!=="then"&&(c==="then"?i.push(l):c==="elif"&&o.length>0?o[o.length-1].body.push(l):a.push(l)),e++}t.push({type:"if",cond:s,then_:i,elif:o,else_:a})}else if(r.startsWith("for ")){let s=r.match(/^for\s+(\w+)\s+in\s+(.+?)(?:\s*;\s*do)?$/);if(s){let i=[];for(e++;e<n.length&&n[e]?.trim()!=="done";){let o=n[e].trim().replace(/^do\s+/,"");o&&o!=="do"&&i.push(o),e++}t.push({type:"for",var:s[1],list:s[2],body:i})}else t.push({type:"cmd",line:r})}else if(r.startsWith("while ")){let s=r.replace(/^while\s+/,"").replace(/;\s*do\s*$/,"").trim(),i=[];for(e++;e<n.length&&n[e]?.trim()!=="done";){let o=n[e].trim().replace(/^do\s+/,"");o&&o!=="do"&&i.push(o),e++}t.push({type:"while",cond:s,body:i})}else t.push({type:"cmd",line:r});e++}return t}async function nc(n,t){let e=await rc(n,t.env.vars,t.env.lastExitCode,t),r=e.match(/^\[?\s*(.+?)\s*\]?$/);if(r){let i=r[1],o=i.match(/^-([fdeznr])\s+(.+)$/);if(o){let[,f,l]=o,u=le(t.cwd,l);if(f==="f")return t.shell.vfs.exists(u)&&t.shell.vfs.stat(u).type==="file";if(f==="d")return t.shell.vfs.exists(u)&&t.shell.vfs.stat(u).type==="directory";if(f==="e")return t.shell.vfs.exists(u);if(f==="z")return(l??"").length===0;if(f==="n")return(l??"").length>0}let a=i.match(/^"?([^"]*)"?\s*(==|!=|=|<|>)\s*"?([^"]*)"?$/);if(a){let[,f,l,u]=a;if(l==="=="||l==="=")return f===u;if(l==="!=")return f!==u}let c=i.match(/^(\S+)\s+(-eq|-ne|-lt|-le|-gt|-ge)\s+(\S+)$/);if(c){let[,f,l,u]=c,h=Number(f),g=Number(u);if(l==="-eq")return h===g;if(l==="-ne")return h!==g;if(l==="-lt")return h<g;if(l==="-le")return h<=g;if(l==="-gt")return h>g;if(l==="-ge")return h>=g}}return((await Bt(e,t.authUser,t.hostname,t.mode,t.cwd,t.shell,void 0,t.env)).exitCode??0)===0}async function ur(n,t){let e={exitCode:0},r="";for(let s of n)if(s.type==="cmd"){let i=await rc(s.line,t.env.vars,t.env.lastExitCode,t),o=/^([A-Za-z_][A-Za-z0-9_]*)=(.*)/,a=i.trim().split(/\s+/);if(a.length>0&&o.test(a[0])&&a.every(l=>o.test(l))){for(let l of a){let u=l.match(o);t.env.vars[u[1]]=u[2]}t.env.lastExitCode=0;continue}let c=await Bt(i,t.authUser,t.hostname,t.mode,t.cwd,t.shell,void 0,t.env);if(t.env.lastExitCode=c.exitCode??0,c.stdout&&(r+=`${c.stdout}
|
|
267
|
+
`),c.stderr)return{...c,stdout:r.trim()};e=c}else if(s.type==="if"){let i=!1;if(await nc(s.cond,t)){let o=await ur(lr(s.then_),t);o.stdout&&(r+=`${o.stdout}
|
|
268
|
+
`),i=!0}else{for(let o of s.elif)if(await nc(o.cond,t)){let a=await ur(lr(o.body),t);a.stdout&&(r+=`${a.stdout}
|
|
269
|
+
`),i=!0;break}if(!i&&s.else_.length>0){let o=await ur(lr(s.else_),t);o.stdout&&(r+=`${o.stdout}
|
|
270
|
+
`)}}}else if(s.type==="for"){let o=(await rc(s.list,t.env.vars,t.env.lastExitCode,t)).trim().split(/\s+/);for(let a of o){t.env.vars[s.var]=a;let c=await ur(lr(s.body),t);if(c.stdout&&(r+=`${c.stdout}
|
|
271
|
+
`),c.closeSession)return c}}else if(s.type==="while"){let i=0;for(;i<1e3&&await nc(s.cond,t);){let o=await ur(lr(s.body),t);if(o.stdout&&(r+=`${o.stdout}
|
|
272
|
+
`),o.closeSession)return o;i++}}return{...e,stdout:r.trim()||e.stdout}}var vd={name:"sh",aliases:["bash"],description:"Execute shell script or command",category:"shell",params:["-c <script>","[<file>]"],run:async n=>{let{args:t,shell:e,cwd:r}=n;if(ne(t,"-c")){let i=t[t.indexOf("-c")+1]??"";if(!i)return{stderr:"sh: -c requires a script",exitCode:1};let o=i.split(/[;\n]/).map(c=>c.trim()).filter(c=>c&&!c.startsWith("#")),a=lr(o);return ur(a,n)}let s=t[0];if(s){let i=le(r,s);if(!e.vfs.exists(i))return{stderr:`sh: ${s}: No such file or directory`,exitCode:1};let a=e.vfs.readFile(i).split(`
|
|
273
|
+
`).map(f=>f.trim()).filter(f=>f&&!f.startsWith("#")),c=lr(a);return ur(c,n)}return{stderr:"sh: invalid usage. Use: sh -c 'cmd' or sh <file>",exitCode:1}}};var kd={name:"shift",description:"Shift positional parameters",category:"shell",params:["[n]"],run:({args:n,env:t})=>{if(!t)return{exitCode:0};let e=parseInt(n[0]??"1",10)||1,r=t.vars.__argv?.split("\0").filter(Boolean)??[];t.vars.__argv=r.slice(e).join("\0");let s=r.slice(e);for(let i=1;i<=9;i++)t.vars[String(i)]=s[i-1]??"";return{exitCode:0}}},Bd={name:"trap",description:"Trap signals and events",category:"shell",params:["[action] [signal...]"],run:({args:n,env:t})=>{if(!t||n.length===0)return{exitCode:0};let e=n[0]??"",r=n.slice(1);for(let s of r)t.vars[`__trap_${s.toUpperCase()}`]=e;return{exitCode:0}}},Rd={name:"return",description:"Return from a shell function",category:"shell",params:["[n]"],run:({args:n,env:t})=>{let e=parseInt(n[0]??"0",10);return t&&(t.lastExitCode=e),{exitCode:e}}};var Nd={name:"sleep",description:"Delay execution",category:"system",params:["<seconds>"],run:async({args:n})=>{let t=parseFloat(n[0]??"1");return Number.isNaN(t)||t<0?{stderr:"sleep: invalid time",exitCode:1}:(await new Promise(e=>setTimeout(e,t*1e3)),{exitCode:0})}};var Pd={name:"sort",description:"Sort lines of text",category:"text",params:["[-r] [-n] [-u] [-k <col>] [file...]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:s})=>{let i=ne(r,["-r"]),o=ne(r,["-n"]),a=ne(r,["-u"]),c=r.filter(y=>!y.startsWith("-")),u=[...(c.length>0?c.map(y=>{try{return $e(n,le(e,y),"sort"),t.vfs.readFile(le(e,y))}catch{return""}}).join(`
|
|
274
274
|
`):s??"").split(`
|
|
275
275
|
`).filter(Boolean)].sort((y,_)=>o?Number(y)-Number(_):y.localeCompare(_)),h=i?u.reverse():u;return{stdout:(a?[...new Set(h)]:h).join(`
|
|
276
|
-
`),exitCode:0}}};var
|
|
277
|
-
`)){let u=l.trim();if(!u||u.startsWith("#"))continue;let h=await Bt(u,t,e,"shell",r,s,void 0,i);if(f=h.exitCode??0,h.closeSession||h.switchUser)return h}return{exitCode:f}}};var
|
|
276
|
+
`),exitCode:0}}};var Td={name:"source",aliases:["."],description:"Execute commands from a file in the current shell environment",category:"shell",params:["<file> [args...]"],run:async({args:n,authUser:t,hostname:e,cwd:r,shell:s,env:i})=>{let o=n[0];if(!o)return{stderr:"source: missing filename",exitCode:1};let a=le(r,o);if(!s.vfs.exists(a))return{stderr:`source: ${o}: No such file or directory`,exitCode:1};let c=s.vfs.readFile(a),f=0;for(let l of c.split(`
|
|
277
|
+
`)){let u=l.trim();if(!u||u.startsWith("#"))continue;let h=await Bt(u,t,e,"shell",r,s,void 0,i);if(f=h.exitCode??0,h.closeSession||h.switchUser)return h}return{exitCode:f}}};var Ld={name:"su",description:"Switch user",category:"users",params:["- <username>"],run:({authUser:n,shell:t,args:e})=>{let r=t.users,s=mn(e,0,{flags:["-"]});return s?!r.isSudoer(n)&&n!=="root"?{stderr:"su: permission denied",exitCode:1}:!r.verifyPassword(s,mn(e,1)??"")&&n!=="root"?{stderr:"su: authentication failure",exitCode:1}:{switchUser:s,nextCwd:`/home/${s}`,exitCode:0}:{stderr:"su: missing username",exitCode:1}}};function LA(n){let{flags:t,flagsWithValues:e,positionals:r}=zt(n,{flags:["-i","-S"],flagsWithValue:["-u","--user"]}),s=t.has("-i"),i=e.get("-u")||e.get("--user")||"root",o=r.length>0?r.join(" "):null;return{targetUser:i,loginShell:s,commandLine:o}}var Ud={name:"sudo",description:"Execute as superuser",category:"users",params:["<command...>"],run:async({authUser:n,hostname:t,mode:e,cwd:r,shell:s,args:i})=>{let{targetUser:o,loginShell:a,commandLine:c}=LA(i);if(n!=="root"&&!s.users.isSudoer(n))return{stderr:"sudo: permission denied",exitCode:1};let f=o||"root",l=`[sudo] password for ${n}: `;return n==="root"?!c&&a?{switchUser:f,nextCwd:`/home/${f}`,exitCode:0}:c?Bt(c,f,t,e,a?`/home/${f}`:r,s):{stderr:"sudo: missing command",exitCode:1}:{sudoChallenge:{username:n,targetUser:f,commandLine:c,loginShell:a,prompt:l},exitCode:0}}};var Dd={name:"tail",description:"Output last lines",category:"text",params:["[-n <lines>] [file...]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:s})=>{let i=en(r,["-n"]),o=typeof i=="string"?parseInt(i,10):10,a=r.filter(l=>!l.startsWith("-")&&l!==i),c=l=>{let u=l.split(`
|
|
278
278
|
`);return u.slice(Math.max(0,u.length-o)).join(`
|
|
279
279
|
`)};if(a.length===0)return{stdout:c(s??""),exitCode:0};let f=[];for(let l of a){let u=le(e,l);try{$e(n,u,"tail"),f.push(c(t.vfs.readFile(u)))}catch{return{stderr:`tail: ${l}: No such file or directory`,exitCode:1}}}return{stdout:f.join(`
|
|
280
|
-
`),exitCode:0}}};var
|
|
281
|
-
`),exitCode:0};for(let[u,h]of Object.entries(l))t.writeFileAsUser(n,le(e,u),h);return{exitCode:0}}return{stderr:"tar: must specify -c, -x, or -t",exitCode:1}}};var
|
|
282
|
-
`),exitCode:i}}};var
|
|
280
|
+
`),exitCode:0}}};var Od={name:"tar",description:"Archive utility",category:"archive",params:["[-czf|-xzf|-tf] <archive> [files...]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=ne(r,["-c"]),i=ne(r,["-x"]),o=ne(r,["-t"]),a=r.findIndex(l=>l.includes("f")),c=a!==-1?r[a+1]:r.find(l=>l.endsWith(".tar")||l.endsWith(".tar.gz")||l.endsWith(".tgz"));if(!c)return{stderr:"tar: no archive specified",exitCode:1};let f=le(e,c);if(s){let l=r.filter(h=>!h.startsWith("-")&&h!==c),u={};for(let h of l){let g=le(e,h);try{if(t.vfs.stat(g).type==="file")u[h]=t.vfs.readFile(g);else{let _=(b,C)=>{for(let L of t.vfs.list(b)){let F=`${b}/${L}`,k=`${C}/${L}`;t.vfs.stat(F).type==="file"?u[k]=t.vfs.readFile(F):_(F,k)}};_(g,h)}}catch{return{stderr:`tar: ${h}: No such file or directory`,exitCode:1}}}return t.writeFileAsUser(n,f,JSON.stringify(u)),{exitCode:0}}if(o||i){let l;try{l=JSON.parse(t.vfs.readFile(f))}catch{return{stderr:`tar: ${c}: cannot open archive`,exitCode:1}}if(o)return{stdout:Object.keys(l).join(`
|
|
281
|
+
`),exitCode:0};for(let[u,h]of Object.entries(l))t.writeFileAsUser(n,le(e,u),h);return{exitCode:0}}return{stderr:"tar: must specify -c, -x, or -t",exitCode:1}}};var Md={name:"tee",description:"Read stdin, write to stdout and files",category:"text",params:["[-a] <file...>"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:s})=>{let i=ne(r,["-a"]),o=r.filter(c=>!c.startsWith("-")),a=s??"";for(let c of o){let f=le(e,c);if(i){let l=(()=>{try{return t.vfs.readFile(f)}catch{return""}})();t.writeFileAsUser(n,f,l+a)}else t.writeFileAsUser(n,f,a)}return{stdout:a,exitCode:0}}};function Vr(n,t,e){if(n[n.length-1]==="]"&&(n=n.slice(0,-1)),n[0]==="["&&(n=n.slice(1)),n.length===0)return!1;if(n[0]==="!")return!Vr(n.slice(1),t,e);let r=n.indexOf("-a");if(r!==-1)return Vr(n.slice(0,r),t,e)&&Vr(n.slice(r+1),t,e);let s=n.indexOf("-o");if(s!==-1)return Vr(n.slice(0,s),t,e)||Vr(n.slice(s+1),t,e);if(n.length===2){let[i,o=""]=n,c=(f=>f.startsWith("/")?f:`${e}/${f}`.replace(/\/+/g,"/"))(o);switch(i){case"-e":return t.vfs.exists(c);case"-f":return t.vfs.exists(c)&&t.vfs.stat(c).type==="file";case"-d":return t.vfs.exists(c)&&t.vfs.stat(c).type==="directory";case"-r":return t.vfs.exists(c);case"-w":return t.vfs.exists(c);case"-x":return t.vfs.exists(c)&&!!(t.vfs.stat(c).mode&73);case"-s":return t.vfs.exists(c)&&t.vfs.stat(c).type==="file"&&t.vfs.stat(c).size>0;case"-z":return o.length===0;case"-n":return o.length>0;case"-L":return t.vfs.isSymlink(c)}}if(n.length===3){let[i="",o,a=""]=n,c=Number(i),f=Number(a);switch(o){case"=":case"==":return i===a;case"!=":return i!==a;case"<":return i<a;case">":return i>a;case"-eq":return c===f;case"-ne":return c!==f;case"-lt":return c<f;case"-le":return c<=f;case"-gt":return c>f;case"-ge":return c>=f}}return n.length===1?(n[0]??"").length>0:!1}var $d={name:"test",aliases:["["],description:"Evaluate conditional expression",category:"shell",params:["<expression>"],run:({args:n,shell:t,cwd:e})=>{try{return{exitCode:Vr([...n],t,e)?0:1}}catch{return{stderr:"test: malformed expression",exitCode:2}}}};var Fd={name:"touch",description:"Create or update files",category:"files",params:["<file>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{if(r.length===0)return{stderr:"touch: missing file operand",exitCode:1};for(let s of r){let i=le(e,s);$e(n,i,"touch"),t.vfs.exists(i)||t.writeFileAsUser(n,i,"")}return{exitCode:0}}};var Hd={name:"tr",description:"Translate or delete characters",category:"text",params:["[-d] <set1> [set2]"],run:({args:n,stdin:t})=>{let e=ne(n,["-d"]),r=n.filter(a=>!a.startsWith("-")),s=r[0]??"",i=r[1]??"",o=t??"";if(e)for(let a of s)o=o.split(a).join("");else if(i)for(let a=0;a<s.length;a++)o=o.split(s[a]).join(i[a]??i[i.length-1]??"");return{stdout:o,exitCode:0}}};var Qd={name:"tree",description:"Display directory tree",category:"navigation",params:["[path]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=le(e,mn(r,0)??e);return $e(n,s,"tree"),{stdout:t.vfs.tree(s),exitCode:0}}};var Wd={name:"true",description:"Return success exit code",category:"shell",params:[],run:()=>({exitCode:0})},qd={name:"false",description:"Return failure exit code",category:"shell",params:[],run:()=>({exitCode:1})};var Kd={name:"type",description:"Describe how a command would be interpreted",category:"shell",params:["<command...>"],run:({args:n,shell:t,env:e})=>{if(n.length===0)return{stderr:"type: missing argument",exitCode:1};let r=(e?.vars?.PATH??"/usr/local/bin:/usr/bin:/bin").split(":"),s=[],i=0;for(let o of n){if(Cn(o)){s.push(`${o} is a shell builtin`);continue}let a=!1;for(let c of r){let f=`${c}/${o}`;if(t.vfs.exists(f)){s.push(`${o} is ${f}`),a=!0;break}}a||(s.push(`${o}: not found`),i=1)}return{stdout:s.join(`
|
|
282
|
+
`),exitCode:i}}};var Vd={name:"uname",description:"Print system information",category:"system",params:["[-a] [-s] [-r] [-m]"],run:({shell:n,args:t})=>{let e=ne(t,["-a"]),r="Linux",s=n.properties?.kernel??"5.15.0",i=n.properties?.arch??"x86_64",o=n.hostname;return e?{stdout:`${r} ${o} ${s} #1 SMP ${i} GNU/Linux`,exitCode:0}:ne(t,["-r"])?{stdout:s,exitCode:0}:ne(t,["-m"])?{stdout:i,exitCode:0}:{stdout:r,exitCode:0}}};var Gd={name:"uniq",description:"Report or filter out repeated lines",category:"text",params:["[-c] [-d] [-u] [file]"],run:({args:n,stdin:t})=>{let e=ne(n,["-c"]),r=ne(n,["-d"]),s=ne(n,["-u"]),i=(t??"").split(`
|
|
283
283
|
`),o=[],a=0;for(;a<i.length;){let c=a;for(;c<i.length&&i[c]===i[a];)c++;let f=c-a,l=i[a];if(r&&f===1){a=c;continue}if(s&&f>1){a=c;continue}o.push(e?`${String(f).padStart(4)} ${l}`:l),a=c}return{stdout:o.join(`
|
|
284
|
-
`),exitCode:0}}};var
|
|
284
|
+
`),exitCode:0}}};var Yd={name:"unset",description:"Remove shell variable",category:"shell",params:["<VAR>"],run:({args:n,env:t})=>{for(let e of n)delete t.vars[e];return{exitCode:0}}};var zd={name:"uptime",description:"Tell how long the system has been running",category:"system",params:["[-p] [-s]"],run:({args:n,shell:t})=>{let e=ne(n,["-p"]),r=ne(n,["-s"]),s=Math.floor((Date.now()-t.startTime)/1e3),i=Math.floor(s/86400),o=Math.floor(s%86400/3600),a=Math.floor(s%3600/60);if(r)return{stdout:new Date(t.startTime).toISOString().slice(0,19).replace("T"," "),exitCode:0};if(e){let h=[];return i>0&&h.push(`${i} day${i>1?"s":""}`),o>0&&h.push(`${o} hour${o>1?"s":""}`),h.push(`${a} minute${a!==1?"s":""}`),{stdout:`up ${h.join(", ")}`,exitCode:0}}let c=new Date().toTimeString().slice(0,8),f=i>0?`${i} day${i>1?"s":""}, ${String(o).padStart(2)}:${String(a).padStart(2,"0")}`:`${String(o).padStart(2)}:${String(a).padStart(2,"0")}`,l=t.users.listActiveSessions().length,u=(Math.random()*.5).toFixed(2);return{stdout:` ${c} up ${f}, ${l} user${l!==1?"s":""}, load average: ${u}, ${u}, ${u}`,exitCode:0}}};var jd={name:"wc",description:"Count words/lines/bytes",category:"text",params:["[-l] [-w] [-c] [file...]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:s})=>{let i=ne(r,["-l"]),o=ne(r,["-w"]),a=ne(r,["-c"]),c=!i&&!o&&!a,f=r.filter(h=>!h.startsWith("-")),l=(h,g)=>{let y=h.split(`
|
|
285
285
|
`).length-(h.endsWith(`
|
|
286
286
|
`)?1:0),_=h.trim().split(/\s+/).filter(Boolean).length,b=Buffer.byteLength(h,"utf8"),C=[];return(c||i)&&C.push(String(y).padStart(7)),(c||o)&&C.push(String(_).padStart(7)),(c||a)&&C.push(String(b).padStart(7)),g&&C.push(` ${g}`),C.join("")};if(f.length===0)return{stdout:l(s??"",""),exitCode:0};let u=[];for(let h of f){let g=le(e,h);try{$e(n,g,"wc");let y=t.vfs.readFile(g);u.push(l(y,h))}catch{return{stderr:`wc: ${h}: No such file or directory`,exitCode:1}}}return{stdout:u.join(`
|
|
287
|
-
`),exitCode:0}}};var
|
|
287
|
+
`),exitCode:0}}};var Xd={name:"wget",description:"File downloader (pure fetch)",category:"network",params:["[options] <url>"],run:async({authUser:n,cwd:t,args:e,shell:r})=>{let{flagsWithValues:s,positionals:i}=zt(e,{flagsWithValue:["-O","--output-document","-o","--output-file","-P","--directory-prefix","--tries","--timeout"]});if(ne(e,["-h","--help"]))return{stdout:["Usage: wget [option]... [URL]..."," -O, --output-document=FILE Write to FILE ('-' for stdout)"," -P, --directory-prefix=DIR Save files in DIR"," -q, --quiet Quiet mode"," -v, --verbose Verbose output (default)"," -c, --continue Continue partial download"," --tries=N Retry N times"," --timeout=N Timeout in seconds"].join(`
|
|
288
288
|
`),exitCode:0};if(ne(e,["-V","--version"]))return{stdout:"GNU Wget 1.21.3 (virtual) built on Fortune GNU/Linux.",exitCode:0};let o=i[0];if(!o)return{stderr:`wget: missing URL
|
|
289
|
-
Usage: wget [OPTION]... [URL]...`,exitCode:1};let a=s.get("-O")??s.get("--output-document")??null,c=s.get("-P")??s.get("--directory-prefix")??null,f=ne(e,["-q","--quiet"]),l=a==="-"?null:a??
|
|
289
|
+
Usage: wget [OPTION]... [URL]...`,exitCode:1};let a=s.get("-O")??s.get("--output-document")??null,c=s.get("-P")??s.get("--directory-prefix")??null,f=ne(e,["-q","--quiet"]),l=a==="-"?null:a??eu(o),u=l?le(t,c?`${c}/${l}`:l):null;u&&$e(n,u,"wget");let h=[];f||(h.push(`--${new Date().toISOString()}-- ${o}`),h.push(`Resolving ${new URL(o).host}...`),h.push(`Connecting to ${new URL(o).host}...`));let g;try{g=await fetch(o,{headers:{"User-Agent":"Wget/1.21.3 (Fortune GNU/Linux)"}})}catch(_){let b=_ instanceof Error?_.message:String(_);return h.push(`wget: unable to resolve host: ${b}`),{stderr:h.join(`
|
|
290
290
|
`),exitCode:4}}if(!g.ok)return h.push(`ERROR ${g.status}: ${g.statusText}`),{stderr:h.join(`
|
|
291
291
|
`),exitCode:8};let y;try{y=await g.text()}catch{return{stderr:"wget: failed to read response",exitCode:1}}if(!f){let _=g.headers.get("content-type")??"application/octet-stream";h.push(`HTTP request sent, awaiting response... ${g.status} ${g.statusText}`),h.push(`Length: ${y.length} [${_}]`)}return a==="-"?{stdout:y,stderr:h.join(`
|
|
292
292
|
`)||void 0,exitCode:0}:u?(r.writeFileAsUser(n,u,y),f||h.push(`Saving to: '${u}'
|
|
293
293
|
${u} 100%[==================>] ${y.length} B`),{stderr:h.join(`
|
|
294
|
-
`)||void 0,exitCode:0}):{stdout:y,exitCode:0}}};var
|
|
295
|
-
`),exitCode:i?1:0}}};function
|
|
296
|
-
`),exitCode:0})};var
|
|
294
|
+
`)||void 0,exitCode:0}):{stdout:y,exitCode:0}}};var Jd={name:"which",description:"Locate a command in PATH",category:"shell",params:["<command...>"],run:({args:n,shell:t,env:e})=>{if(n.length===0)return{stderr:"which: missing argument",exitCode:1};let r=(e?.vars?.PATH??"/usr/local/bin:/usr/bin:/bin").split(":"),s=[],i=!1;for(let o of n){let a=!1;for(let c of r){let f=`${c}/${o}`;if(t.vfs.exists(f)&&t.vfs.stat(f).type==="file"){s.push(f),a=!0;break}}a||(i=!0)}return s.length===0?{exitCode:1}:{stdout:s.join(`
|
|
295
|
+
`),exitCode:i?1:0}}};function qs(n){let t=n.toLocaleString("en-US",{weekday:"short"}),e=n.toLocaleString("en-US",{month:"short"}),r=n.getDate().toString().padStart(2,"0"),s=n.getHours().toString().padStart(2,"0"),i=n.getMinutes().toString().padStart(2,"0"),o=n.getSeconds().toString().padStart(2,"0"),a=n.getFullYear();return`${t} ${e} ${r} ${s}:${i}:${o} ${a}`}var Zd={name:"who",description:"Show active sessions",category:"system",params:[],run:({shell:n})=>({stdout:n.users.listActiveSessions().map(e=>{let r=new Date(e.startedAt),s=Number.isNaN(r.getTime())?e.startedAt:qs(r);return`${e.username} ${e.tty} ${s} (${e.remoteAddress||"unknown"})`}).join(`
|
|
296
|
+
`),exitCode:0})};var eh={name:"whoami",description:"Print current user",category:"system",params:[],run:({authUser:n})=>({stdout:n,exitCode:0})};var th={name:"xargs",description:"Build and execute command lines from stdin",category:"text",params:["[command] [args...]"],run:async({authUser:n,hostname:t,mode:e,cwd:r,args:s,stdin:i,shell:o,env:a})=>{let c=s[0]??"echo",f=s.slice(1),l=(i??"").trim().split(/\s+/).filter(Boolean);if(l.length===0)return{exitCode:0};let u=[c,...f,...l].join(" ");return Bt(u,n,t,e,r,o,void 0,a)}};var UA=[md,cu,qu,Qd,au,Fd,bd,Gu,uu,Yu,Wu,fu,Cu,ku,xd,su,Pd,Gd,jd,Pu,Dd,hu,Hd,Md,th,Eu,Od,Ru,Nu,ou,eh,Zd,$u,Hu,Bu,Vd,gd,Qu,Au,bu,pu,Nd,hd,xu,Su,Iu,od,Yd,vd,lu,wu,ju,Fu,du,Xd,jl,dd,mu,Ud,Ld,ad,ru,iu,_u,yu,Jd,Kd,Vu,Jl,Zl,$d,Td,Mu,pd,yd,gu,kd,Bd,Rd,Wd,qd,ld,ud,fd,_d,zd,vu,Ku],nh=[],Ui=new Map,Ks=null,DA=Ou(()=>sc().map(n=>n.name));function ic(){Ui.clear();for(let n of sc()){Ui.set(n.name,n);for(let t of n.aliases??[])Ui.set(t,n)}Ks=Array.from(Ui.keys()).sort()}function sc(){return[...UA,...nh,DA]}function Za(n){let t={...n,name:n.name.trim().toLowerCase(),aliases:n.aliases?.map(r=>r.trim().toLowerCase())};if([t.name,...t.aliases??[]].some(r=>r.length===0||/\s/.test(r)))throw new Error("Command names must be non-empty and contain no spaces");nh.push(t),ic()}function ec(n,t,e){return{name:n,params:t,run:e}}function tc(){return Ks||ic(),Ks}function Ya(){return sc()}function Cn(n){return Ks||ic(),Ui.get(n.toLowerCase())}var Gr=Vt(require("node:os"),1);function ye(n,t,e=493){n.exists(t)||n.mkdir(t,e)}function st(n,t,e,r=420){n.exists(t)||n.writeFile(t,e,{mode:r})}function OA(n,t,e){ye(n,"/etc"),st(n,"/etc/os-release",`${['NAME="Fortune GNU/Linux"',`PRETTY_NAME="${e.os}"`,"ID=fortune","ID_LIKE=debian",'HOME_URL="https://github.com/itsrealfortune/typescript-virtual-container"',"VERSION_CODENAME=aurora",'VERSION_ID="1.0"'].join(`
|
|
297
297
|
`)}
|
|
298
|
-
`),
|
|
299
|
-
`),
|
|
300
|
-
`),
|
|
298
|
+
`),st(n,"/etc/debian_version",`12.0
|
|
299
|
+
`),st(n,"/etc/hostname",`${t}
|
|
300
|
+
`),st(n,"/etc/shells",`/bin/sh
|
|
301
301
|
/bin/bash
|
|
302
302
|
/usr/bin/bash
|
|
303
|
-
`),
|
|
303
|
+
`),st(n,"/etc/profile",`${["export PATH=/usr/local/bin:/usr/bin:/bin","export PS1='\\u@\\h:\\w\\$ '"].join(`
|
|
304
304
|
`)}
|
|
305
|
-
`),
|
|
306
|
-
`),
|
|
307
|
-
`)),ye(n,"/etc/apt"),ye(n,"/etc/apt/sources.list.d"),
|
|
305
|
+
`),st(n,"/etc/issue",`Fortune GNU/Linux 1.0 \\n \\l
|
|
306
|
+
`),st(n,"/etc/motd",["",`Welcome to ${e.os}`,`Kernel: ${e.kernel}`,""].join(`
|
|
307
|
+
`)),ye(n,"/etc/apt"),ye(n,"/etc/apt/sources.list.d"),st(n,"/etc/apt/sources.list",`${["# Fortune GNU/Linux package sources","deb [virtual] fortune://packages.fortune.local aurora main contrib","deb [virtual] fortune://security.fortune.local aurora-security main"].join(`
|
|
308
308
|
`)}
|
|
309
|
-
`),ye(n,"/etc/network"),
|
|
309
|
+
`),ye(n,"/etc/network"),st(n,"/etc/network/interfaces",`${["auto lo","iface lo inet loopback","","auto eth0","iface eth0 inet dhcp"].join(`
|
|
310
310
|
`)}
|
|
311
|
-
`),
|
|
311
|
+
`),st(n,"/etc/resolv.conf",`nameserver 1.1.1.1
|
|
312
312
|
nameserver 8.8.8.8
|
|
313
|
-
`),
|
|
313
|
+
`),st(n,"/etc/hosts",`${["127.0.0.1 localhost",`127.0.1.1 ${t}`,"::1 localhost ip6-localhost ip6-loopback"].join(`
|
|
314
314
|
`)}
|
|
315
|
-
`),ye(n,"/etc/cron.d"),ye(n,"/etc/init.d"),ye(n,"/etc/systemd"),ye(n,"/etc/systemd/system")}function
|
|
315
|
+
`),ye(n,"/etc/cron.d"),ye(n,"/etc/init.d"),ye(n,"/etc/systemd"),ye(n,"/etc/systemd/system")}function oc(n,t){let e=t.listUsers(),r=["root:x:0:0:root:/root:/bin/bash","daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin","www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin","nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin"],s=1e3;for(let a of e)a!=="root"&&(r.push(`${a}:x:${s}:${s}::/home/${a}:/bin/bash`),s++);n.writeFile("/etc/passwd",`${r.join(`
|
|
316
316
|
`)}
|
|
317
317
|
`);let i=["root:x:0:","daemon:x:1:",`sudo:x:27:${e.filter(a=>t.isSudoer(a)).join(",")}`,`users:x:100:${e.filter(a=>a!=="root").join(",")}`,"nogroup:x:65534:"];n.writeFile("/etc/group",`${i.join(`
|
|
318
318
|
`)}
|
|
319
319
|
`);let o=["root:*:19000:0:99999:7:::","daemon:*:19000:0:99999:7:::"];for(let a of e)a!=="root"&&o.push(`${a}:!:19000:0:99999:7:::`);n.writeFile("/etc/shadow",`${o.join(`
|
|
320
320
|
`)}
|
|
321
|
-
`,{mode:416})}function
|
|
321
|
+
`,{mode:416})}function rh(n){let t=n.match(/(\d+)$/);return 1e3+(t?.[1]?parseInt(t[1],10):0)}function ih(n,t,e,r,s,i,o){let a=`/proc/${t}`;ye(n,a),ye(n,`${a}/fd`),ye(n,`${a}/fdinfo`);let c=Math.floor((Date.now()-new Date(i).getTime())/1e3);n.writeFile(`${a}/cmdline`,`${s.replace(/\s+/g,"\0")}\0`),n.writeFile(`${a}/comm`,s.split(/\s+/)[0]??"bash"),n.writeFile(`${a}/status`,`${[`Name: ${s.split(/\s+/)[0]??"bash"}`,"State: S (sleeping)",`Pid: ${t}`,"PPid: 1","Uid: 0 0 0 0","Gid: 0 0 0 0","VmRSS: 4096 kB","VmSize: 16384 kB","Threads: 1"].join(`
|
|
322
322
|
`)}
|
|
323
323
|
`),n.writeFile(`${a}/stat`,`${t} (${s.split(/\s+/)[0]??"bash"}) S 1 ${t} ${t} 0 -1 4194304 0 0 0 0 ${c} 0 0 0 20 0 1 0 0 16384 4096 0
|
|
324
|
-
`),n.writeFile(`${a}/environ`,`${Object.entries(o).map(([f,l])=>`${f}=${l}`).join("\0")}\0`),n.writeFile(`${a}/cwd`,`/home/${e}\0`),n.writeFile(`${a}/exe`,"/bin/bash\0"),n.writeFile(`${a}/fd/0`,""),n.writeFile(`${a}/fd/1`,""),n.writeFile(`${a}/fd/2`,"")}function
|
|
325
|
-
`);let o=Math.floor(
|
|
324
|
+
`),n.writeFile(`${a}/environ`,`${Object.entries(o).map(([f,l])=>`${f}=${l}`).join("\0")}\0`),n.writeFile(`${a}/cwd`,`/home/${e}\0`),n.writeFile(`${a}/exe`,"/bin/bash\0"),n.writeFile(`${a}/fd/0`,""),n.writeFile(`${a}/fd/1`,""),n.writeFile(`${a}/fd/2`,"")}function Vs(n,t,e,r,s){ye(n,"/proc");let i=Math.floor((Date.now()-r)/1e3);n.writeFile("/proc/uptime",`${i}.00 ${Math.floor(i*.9)}.00
|
|
325
|
+
`);let o=Math.floor(Gr.totalmem()/1024),a=Math.floor(Gr.freemem()/1024),c=Math.floor(a*.95);n.writeFile("/proc/meminfo",`${[`MemTotal: ${String(o).padStart(10)} kB`,`MemFree: ${String(a).padStart(10)} kB`,`MemAvailable: ${String(c).padStart(10)} kB`,`Buffers: ${String(Math.floor(o*.02)).padStart(10)} kB`,`Cached: ${String(Math.floor(o*.15)).padStart(10)} kB`,`SwapTotal: ${String(Math.floor(o*.5)).padStart(10)} kB`,`SwapFree: ${String(Math.floor(o*.5)).padStart(10)} kB`].join(`
|
|
326
326
|
`)}
|
|
327
|
-
`);let f=
|
|
327
|
+
`);let f=Gr.cpus(),l=[];for(let b=0;b<f.length;b++){let C=f[b];if(!C)continue;let L=C.speed.toFixed(3);l.push(`processor : ${b}`,`model name : ${C.model}`,`cpu MHz : ${L}`,"cache size : 8192 KB","")}n.writeFile("/proc/cpuinfo",`${l.join(`
|
|
328
328
|
`)}
|
|
329
329
|
`),n.writeFile("/proc/version",`Linux version ${t.kernel} (fortune@build) (gcc version 12.2.0) #1 SMP
|
|
330
330
|
`),n.writeFile("/proc/hostname",`${e}
|
|
331
331
|
`);let u=(Math.random()*.5).toFixed(2),h=1+(s?.length??0);n.writeFile("/proc/loadavg",`${u} ${u} ${u} ${h}/${h} 1
|
|
332
|
-
`),ye(n,"/proc/net"),
|
|
332
|
+
`),ye(n,"/proc/net"),st(n,"/proc/net/dev",`${["Inter-| Receive | Transmit"," face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed"," lo: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"," eth0: 131072 1024 0 0 0 0 0 0 65536 512 0 0 0 0 0 0"].join(`
|
|
333
333
|
`)}
|
|
334
|
-
`),
|
|
334
|
+
`),ih(n,1,"root","pts/0","/sbin/init",new Date(r).toISOString(),{});let g=s??[];for(let b of g){let C=rh(b.tty);ih(n,C,b.username,b.tty,"bash",b.startedAt,{USER:b.username,HOME:`/home/${b.username}`,TERM:"xterm-256color",SHELL:"/bin/bash"})}let y=g.length>0?rh(g[g.length-1].tty):1;if(n.exists("/proc/self"))try{n.remove("/proc/self")}catch{}let _=`/proc/${y}`;if(n.exists(_)){ye(n,"/proc/self"),ye(n,"/proc/self/fd");for(let b of n.list(_)){let C=`${_}/${b}`,L=`/proc/self/${b}`;try{n.stat(C).type==="file"&&n.writeFile(L,n.readFile(C))}catch{}}n.writeFile("/proc/self/status",n.exists(`${_}/status`)?n.readFile(`${_}/status`):"")}else ye(n,"/proc/self"),n.writeFile("/proc/self/cmdline","bash\0"),n.writeFile("/proc/self/comm","bash"),n.writeFile("/proc/self/status",`Name: bash
|
|
335
335
|
State: S (sleeping)
|
|
336
336
|
Pid: 1
|
|
337
337
|
PPid: 0
|
|
338
|
-
`),n.writeFile("/proc/self/environ",""),n.writeFile("/proc/self/cwd","/root\0"),n.writeFile("/proc/self/exe","/bin/bash\0")}function
|
|
339
|
-
`),
|
|
340
|
-
`),
|
|
341
|
-
`),ye(n,"/sys/class"),ye(n,"/sys/class/net"),ye(n,"/sys/kernel"),
|
|
342
|
-
`),
|
|
343
|
-
`),
|
|
344
|
-
`)}function
|
|
338
|
+
`),n.writeFile("/proc/self/environ",""),n.writeFile("/proc/self/cwd","/root\0"),n.writeFile("/proc/self/exe","/bin/bash\0")}function MA(n,t){ye(n,"/sys"),ye(n,"/sys/devices"),ye(n,"/sys/devices/virtual"),ye(n,"/sys/devices/virtual/dmi"),ye(n,"/sys/devices/virtual/dmi/id"),st(n,"/sys/devices/virtual/dmi/id/sys_vendor",`Fortune Systems
|
|
339
|
+
`),st(n,"/sys/devices/virtual/dmi/id/product_name",`VirtualContainer v1
|
|
340
|
+
`),st(n,"/sys/devices/virtual/dmi/id/board_name",`fortune-board
|
|
341
|
+
`),ye(n,"/sys/class"),ye(n,"/sys/class/net"),ye(n,"/sys/kernel"),st(n,"/sys/kernel/hostname",`fortune-vm
|
|
342
|
+
`),st(n,"/sys/kernel/osrelease",`${t.kernel}
|
|
343
|
+
`),st(n,"/sys/kernel/ostype",`Linux
|
|
344
|
+
`)}function $A(n){ye(n,"/dev"),st(n,"/dev/null","",438),st(n,"/dev/zero","",438),st(n,"/dev/random","",292),st(n,"/dev/urandom","",292),ye(n,"/dev/pts"),ye(n,"/dev/shm")}function FA(n){ye(n,"/usr"),ye(n,"/usr/bin"),ye(n,"/usr/sbin"),ye(n,"/usr/local"),ye(n,"/usr/local/bin"),ye(n,"/usr/local/lib"),ye(n,"/usr/local/share"),ye(n,"/usr/share"),ye(n,"/usr/share/doc"),ye(n,"/usr/share/man"),ye(n,"/usr/share/man/man1"),ye(n,"/usr/lib");let t=["sh","bash","ls","cat","echo","grep","find","sort","head","tail","cut","tr","sed","awk","wc","tee","tar","gzip","gunzip","touch","mkdir","rm","mv","cp","chmod","ln","pwd","env","date","sleep","id","whoami","hostname","uname","ps","kill","df","du","curl","wget","nano","diff","uniq","xargs","base64"];for(let e of t)st(n,`/usr/bin/${e}`,`#!/bin/sh
|
|
345
345
|
exec builtin ${e} "$@"
|
|
346
|
-
`,493);
|
|
346
|
+
`,493);st(n,"/usr/bin/lsb_release",`#!/bin/sh
|
|
347
347
|
exec lsb_release "$@"
|
|
348
|
-
`,493)}function
|
|
349
|
-
`),
|
|
348
|
+
`,493)}function HA(n){ye(n,"/var"),ye(n,"/var/log"),ye(n,"/var/tmp"),ye(n,"/var/run"),ye(n,"/var/cache"),ye(n,"/var/cache/apt"),ye(n,"/var/cache/apt/archives"),ye(n,"/var/lib"),ye(n,"/var/lib/apt"),ye(n,"/var/lib/apt/lists"),ye(n,"/var/lib/dpkg"),ye(n,"/var/lib/dpkg/info"),st(n,"/var/lib/dpkg/status",""),st(n,"/var/lib/dpkg/available",""),st(n,"/var/log/syslog",`${new Date().toUTCString()} fortune kernel: Virtual container started
|
|
349
|
+
`),st(n,"/var/log/auth.log",""),st(n,"/var/log/dpkg.log",""),st(n,"/var/log/apt/history.log",""),st(n,"/var/log/apt/term.log","")}function QA(n){n.exists("/bin")||n.symlink("/usr/bin","/bin"),n.exists("/sbin")||n.symlink("/usr/sbin","/sbin"),n.exists("/lib")||ye(n,"/lib"),n.exists("/lib64")||ye(n,"/lib64")}function WA(n){ye(n,"/tmp",1023)}function qA(n){ye(n,"/root",448),st(n,"/root/.bashrc",`${["# root .bashrc","export PS1='\\[\\033[0;31m\\]\\u@\\h\\[\\033[0m\\]:\\[\\033[0;34m\\]\\w\\[\\033[0m\\]# '","export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","alias ll='ls -la'","alias la='ls -A'"].join(`
|
|
350
350
|
`)}
|
|
351
|
-
`),
|
|
352
|
-
`),n.exists("/home/root")||n.symlink("/root","/home/root")}function
|
|
351
|
+
`),st(n,"/root/.profile",`[ -f ~/.bashrc ] && . ~/.bashrc
|
|
352
|
+
`),n.exists("/home/root")||n.symlink("/root","/home/root")}function KA(n){ye(n,"/opt"),ye(n,"/srv"),ye(n,"/mnt"),ye(n,"/media")}function sh(n,t,e,r,s){OA(n,e,r),MA(n,r),$A(n),FA(n),HA(n),QA(n),WA(n),qA(n),KA(n),Vs(n,r,e,s,[]),oc(n,t)}function oh(n){return n==="1"||n==="true"}function ah(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}function VA(){return oh(process.env.DEV_MODE)||oh(process.env.RENDER_PERF)}function Xn(n){let t=VA();if(!t)return{enabled:t,mark:()=>{},done:()=>{}};let e=ah(),r=i=>{let o=ah()-e;console.log(`[perf][${n}] ${i}: ${o.toFixed(1)}ms`)};return{enabled:t,mark:r,done:(i="done")=>{r(i)}}}var gh=require("node:events"),Jn=Vt(require("node:fs"),1),vn=Vt(require("node:path"),1),dr=require("node:zlib");var fc=Buffer.from([86,70,83,33]),GA=1,ch=1,fh=2,ac=class{chunks=[];write(t){this.chunks.push(t)}writeUint8(t){let e=Buffer.allocUnsafe(1);e.writeUInt8(t,0),this.chunks.push(e)}writeUint16(t){let e=Buffer.allocUnsafe(2);e.writeUInt16LE(t,0),this.chunks.push(e)}writeUint32(t){let e=Buffer.allocUnsafe(4);e.writeUInt32LE(t,0),this.chunks.push(e)}writeFloat64(t){let e=Buffer.allocUnsafe(8);e.writeDoubleBE(t,0),this.chunks.push(e)}writeString(t){let e=Buffer.from(t,"utf8");this.writeUint16(e.length),this.chunks.push(e)}writeBytes(t){this.writeUint32(t.length),this.chunks.push(t)}toBuffer(){return Buffer.concat(this.chunks)}};function lh(n,t){if(t.type==="file"){let e=t;n.writeUint8(ch),n.writeString(e.name),n.writeUint32(e.mode),n.writeFloat64(e.createdAt.getTime()),n.writeFloat64(e.updatedAt.getTime()),n.writeUint8(e.compressed?1:0),n.writeBytes(e.content)}else{let e=t;n.writeUint8(fh),n.writeString(e.name),n.writeUint32(e.mode),n.writeFloat64(e.createdAt.getTime()),n.writeFloat64(e.updatedAt.getTime());let r=Array.from(e.children.values());n.writeUint32(r.length);for(let s of r)lh(n,s)}}function uh(n){let t=new ac;return t.write(fc),t.writeUint8(GA),lh(t,n),t.toBuffer()}var cc=class{constructor(t){this.buf=t}buf;pos=0;readUint8(){return this.buf.readUInt8(this.pos++)}readUint16(){let t=this.buf.readUInt16LE(this.pos);return this.pos+=2,t}readUint32(){let t=this.buf.readUInt32LE(this.pos);return this.pos+=4,t}readFloat64(){let t=this.buf.readDoubleBE(this.pos);return this.pos+=8,t}readString(){let t=this.readUint16(),e=this.buf.toString("utf8",this.pos,this.pos+t);return this.pos+=t,e}readBytes(){let t=this.readUint32(),e=this.buf.slice(this.pos,this.pos+t);return this.pos+=t,e}remaining(){return this.buf.length-this.pos}};function dh(n){let t=n.readUint8(),e=n.readString(),r=n.readUint32(),s=new Date(n.readFloat64()),i=new Date(n.readFloat64());if(t===ch){let o=n.readUint8()===1,a=n.readBytes();return{type:"file",name:e,mode:r,createdAt:s,updatedAt:i,compressed:o,content:a}}if(t===fh){let o=n.readUint32(),a=new Map;for(let c=0;c<o;c++){let f=dh(n);a.set(f.name,f)}return{type:"directory",name:e,mode:r,createdAt:s,updatedAt:i,children:a}}throw new Error(`[VFS binary] Unknown node type: 0x${t.toString(16)}`)}function hh(n){if(n.length<5)throw new Error("[VFS binary] Buffer too short");if(!n.slice(0,4).equals(fc))throw new Error("[VFS binary] Invalid magic \u2014 not a VFS binary snapshot");let e=new cc(n);for(let s=0;s<5;s++)e.readUint8();let r=dh(e);if(r.type!=="directory")throw new Error("[VFS binary] Root node must be a directory");return r}function ph(n){return n.length>=4&&n.slice(0,4).equals(fc)}var Gs=Vt(require("node:path"),1);function Et(n){if(!n||n.trim()==="")return"/";let t=Gs.posix.normalize(n.startsWith("/")?n:`/${n}`);return t===""?"/":t}function YA(n){return n.split("/").filter(Boolean)}function Ft(n,t){let e=Et(t);if(e==="/")return n;let r=YA(e),s=n;for(let i of r){if(s.type!=="directory")throw new Error(`Path '${e}' does not exist.`);let o=s.children.get(i);if(!o)throw new Error(`Path '${e}' does not exist.`);s=o}return s}function Yr(n,t,e,r){let s=Et(t);if(s==="/")throw new Error("Root path has no parent directory.");let i=Gs.posix.dirname(s),o=Gs.posix.basename(s);if(!o)throw new Error(`Invalid path '${t}'.`);e&&r(i);let a=Ft(n,i);if(a.type!=="directory")throw new Error(`Parent path '${i}' is not a directory.`);return{parent:a,name:o}}var lc=class n extends gh.EventEmitter{root;mode;snapshotFile;constructor(t={}){if(super(),this.mode=t.mode??"memory",this.mode==="fs"){if(!t.snapshotPath)throw new Error('VirtualFileSystem: "snapshotPath" is required when mode is "fs".');this.snapshotFile=vn.resolve(t.snapshotPath,"vfs-snapshot.vfsb")}else this.snapshotFile=null;this.root=this.makeDir("",493)}makeDir(t,e){let r=new Date;return{type:"directory",name:t,mode:e,createdAt:r,updatedAt:r,children:new Map}}makeFile(t,e,r,s){let i=new Date;return{type:"file",name:t,content:e,mode:r,compressed:s,createdAt:i,updatedAt:i}}mkdirRecursive(t,e){let r=Et(t);if(r==="/")return;let s=r.split("/").filter(Boolean),i=this.root,o="";for(let a of s){o+=`/${a}`;let c=i.children.get(a);if(!c)c=this.makeDir(a,e),i.children.set(a,c),this.emit("dir:create",{path:o,mode:e});else if(c.type!=="directory")throw new Error(`Cannot create directory '${o}': path is a file.`);i=c}}async restoreMirror(){if(!(this.mode!=="fs"||!this.snapshotFile)&&Jn.existsSync(this.snapshotFile))try{let t=Jn.readFileSync(this.snapshotFile);if(ph(t))this.root=hh(t);else{let e=JSON.parse(t.toString("utf8"));this.root=this.deserializeDir(e.root,""),console.info("[VirtualFileSystem] Migrating legacy JSON snapshot to binary format.")}this.emit("snapshot:restore",{path:this.snapshotFile})}catch(t){console.warn(`[VirtualFileSystem] Could not restore snapshot from ${this.snapshotFile}:`,t instanceof Error?t.message:String(t))}}async flushMirror(){if(this.mode!=="fs"||!this.snapshotFile){this.emit("mirror:flush");return}let t=vn.dirname(this.snapshotFile);Jn.mkdirSync(t,{recursive:!0});let e=uh(this.root);Jn.writeFileSync(this.snapshotFile,e),this.emit("mirror:flush",{path:this.snapshotFile})}getMode(){return this.mode}getSnapshotPath(){return this.snapshotFile}mkdir(t,e=493){let r=Et(t),s=(()=>{try{return Ft(this.root,r)}catch{return null}})();if(s&&s.type!=="directory")throw new Error(`Cannot create directory '${r}': path is a file.`);this.mkdirRecursive(r,e)}writeFile(t,e,r={}){let s=Et(t),{parent:i,name:o}=Yr(this.root,s,!0,h=>this.mkdirRecursive(h,493)),a=i.children.get(o);if(a?.type==="directory")throw new Error(`Cannot write file '${s}': path is a directory.`);let c=Buffer.isBuffer(e)?e:Buffer.from(e,"utf8"),f=r.compress??!1,l=f?(0,dr.gzipSync)(c):c,u=r.mode??420;if(a){let h=a;h.content=l,h.compressed=f,h.mode=u,h.updatedAt=new Date}else i.children.set(o,this.makeFile(o,l,u,f));this.emit("file:write",{path:s,size:l.length})}readFile(t){let e=Et(t),r=Ft(this.root,e);if(r.type!=="file")throw new Error(`Cannot read '${t}': not a file.`);let s=r,i=s.compressed?(0,dr.gunzipSync)(s.content):s.content;return this.emit("file:read",{path:e,size:i.length}),i.toString("utf8")}readFileRaw(t){let e=Et(t),r=Ft(this.root,e);if(r.type!=="file")throw new Error(`Cannot read '${t}': not a file.`);let s=r,i=s.compressed?(0,dr.gunzipSync)(s.content):s.content;return this.emit("file:read",{path:e,size:i.length}),i}exists(t){try{return Ft(this.root,Et(t)),!0}catch{return!1}}chmod(t,e){Ft(this.root,Et(t)).mode=e}stat(t){let e=Et(t),r=Ft(this.root,e),s=e==="/"?"":vn.posix.basename(e);if(r.type==="file"){let o=r;return{type:"file",name:s,path:e,mode:o.mode,createdAt:o.createdAt,updatedAt:o.updatedAt,compressed:o.compressed,size:o.content.length}}let i=r;return{type:"directory",name:s,path:e,mode:i.mode,createdAt:i.createdAt,updatedAt:i.updatedAt,childrenCount:i.children.size}}list(t="/"){let e=Et(t),r=Ft(this.root,e);if(r.type!=="directory")throw new Error(`Cannot list '${t}': not a directory.`);return Array.from(r.children.keys()).sort()}tree(t="/"){let e=Et(t),r=Ft(this.root,e);if(r.type!=="directory")throw new Error(`Cannot render tree for '${t}': not a directory.`);let s=t==="/"?"/":vn.posix.basename(e);return this.renderTreeLines(r,s)}renderTreeLines(t,e){let r=[e],s=Array.from(t.children.keys()).sort();for(let i=0;i<s.length;i++){let o=s[i],a=t.children.get(o),c=i===s.length-1,f=c?"\u2514\u2500\u2500 ":"\u251C\u2500\u2500 ",l=c?" ":"\u2502 ";if(r.push(`${f}${o}`),a.type==="directory"){let u=this.renderTreeLines(a,"").split(`
|
|
353
353
|
`).slice(1).map(h=>`${l}${h}`);r.push(...u)}}return r.join(`
|
|
354
|
-
`)}getUsageBytes(t="/"){return this.computeUsage(
|
|
354
|
+
`)}getUsageBytes(t="/"){return this.computeUsage(Ft(this.root,Et(t)))}computeUsage(t){if(t.type==="file")return t.content.length;let e=0;for(let r of t.children.values())e+=this.computeUsage(r);return e}compressFile(t){let e=Ft(this.root,Et(t));if(e.type!=="file")throw new Error(`Cannot compress '${t}': not a file.`);let r=e;r.compressed||(r.content=(0,dr.gzipSync)(r.content),r.compressed=!0,r.updatedAt=new Date)}decompressFile(t){let e=Ft(this.root,Et(t));if(e.type!=="file")throw new Error(`Cannot decompress '${t}': not a file.`);let r=e;r.compressed&&(r.content=(0,dr.gunzipSync)(r.content),r.compressed=!1,r.updatedAt=new Date)}symlink(t,e){let r=Et(e),s=t.startsWith("/")?Et(t):t,{parent:i,name:o}=Yr(this.root,r,!0,c=>this.mkdirRecursive(c,493)),a={type:"file",name:o,content:Buffer.from(s,"utf8"),mode:41471,compressed:!1,createdAt:new Date,updatedAt:new Date};i.children.set(o,a),this.emit("symlink:create",{link:r,target:s})}isSymlink(t){try{let e=Ft(this.root,Et(t));return e.type==="file"&&e.mode===41471}catch{return!1}}resolveSymlink(t,e=8){let r=Et(t);for(let s=0;s<e;s++){try{let i=Ft(this.root,r);if(i.type==="file"&&i.mode===41471){let o=i.content.toString("utf8");r=o.startsWith("/")?o:Et(vn.posix.join(vn.posix.dirname(r),o));continue}}catch{break}return r}throw new Error(`Too many levels of symbolic links: ${t}`)}remove(t,e={}){let r=Et(t);if(r==="/")throw new Error("Cannot remove root directory.");let s=Ft(this.root,r);if(s.type==="directory"){let a=s;if(!e.recursive&&a.children.size>0)throw new Error(`Directory '${r}' is not empty. Use recursive option.`)}let{parent:i,name:o}=Yr(this.root,r,!1,()=>{});i.children.delete(o),this.emit("node:remove",{path:r})}move(t,e){let r=Et(t),s=Et(e);if(r==="/"||s==="/")throw new Error("Cannot move root directory.");let i=Ft(this.root,r);if(this.exists(s))throw new Error(`Destination '${s}' already exists.`);this.mkdirRecursive(vn.posix.dirname(s),493);let{parent:o,name:a}=Yr(this.root,s,!1,()=>{}),{parent:c,name:f}=Yr(this.root,r,!1,()=>{});c.children.delete(f),i.name=a,o.children.set(a,i)}toSnapshot(){return{root:this.serializeDir(this.root)}}serializeDir(t){let e=[];for(let r of t.children.values())e.push(r.type==="file"?this.serializeFile(r):this.serializeDir(r));return{type:"directory",name:t.name,mode:t.mode,createdAt:t.createdAt.toISOString(),updatedAt:t.updatedAt.toISOString(),children:e}}serializeFile(t){return{type:"file",name:t.name,mode:t.mode,createdAt:t.createdAt.toISOString(),updatedAt:t.updatedAt.toISOString(),compressed:t.compressed,contentBase64:t.content.toString("base64")}}static fromSnapshot(t){let e=new n;return e.root=e.deserializeDir(t.root,""),e}importSnapshot(t){this.root=this.deserializeDir(t.root,""),this.emit("snapshot:import")}deserializeDir(t,e){let r={type:"directory",name:e,mode:t.mode,createdAt:new Date(t.createdAt),updatedAt:new Date(t.updatedAt),children:new Map};for(let s of t.children)if(s.type==="file"){let i=s;r.children.set(i.name,{type:"file",name:i.name,mode:i.mode,createdAt:new Date(i.createdAt),updatedAt:new Date(i.updatedAt),compressed:i.compressed,content:Buffer.from(i.contentBase64,"base64")})}else{let i=this.deserializeDir(s,s.name);r.children.set(s.name,i)}return r}},uc=lc;var dc=[{name:"vim",version:"2:9.0.1378-2",section:"editors",description:"Vi IMproved - enhanced vi editor",shortDesc:"Vi IMproved",installedSizeKb:3812,files:[{path:"/usr/bin/vim",content:`#!/bin/sh
|
|
355
355
|
echo 'vim: use nano for editing in this environment'
|
|
356
356
|
`,mode:493},{path:"/usr/bin/vi",content:`#!/bin/sh
|
|
357
357
|
exec vim "$@"
|
|
@@ -436,19 +436,19 @@ echo 'systemd is not running in this virtual container.'
|
|
|
436
436
|
exit 1
|
|
437
437
|
`,mode:493},{path:"/usr/bin/journalctl",content:`#!/bin/sh
|
|
438
438
|
echo 'journalctl: virtual stub'
|
|
439
|
-
`,mode:493}]}],
|
|
439
|
+
`,mode:493}]}],Ys=class{constructor(t,e){this.vfs=t;this.users=e}vfs;users;installed=new Map;registryPath="/var/lib/dpkg/status";logPath="/var/log/dpkg.log";aptLogPath="/var/log/apt/history.log";load(){if(!this.vfs.exists(this.registryPath))return;let t=this.vfs.readFile(this.registryPath);if(!t.trim())return;let e=t.split(/\n\n+/);for(let r of e){if(!r.trim())continue;let s=this.parseFields(r),i=s.Package;i&&this.installed.set(i,{name:i,version:s.Version??"unknown",architecture:s.Architecture??"amd64",maintainer:s.Maintainer??"Fortune Maintainers",description:s.Description??"",section:s.Section??"misc",installedSizeKb:Number(s["Installed-Size"]??0),installedAt:s["X-Installed-At"]??new Date().toISOString(),files:(s["X-Files"]??"").split("|").filter(Boolean)})}}persist(){let t=[];for(let e of this.installed.values())t.push([`Package: ${e.name}`,"Status: install ok installed","Priority: optional",`Section: ${e.section}`,`Installed-Size: ${e.installedSizeKb}`,`Maintainer: ${e.maintainer}`,`Architecture: ${e.architecture}`,`Version: ${e.version}`,`Description: ${e.description}`,`X-Installed-At: ${e.installedAt}`,`X-Files: ${e.files.join("|")}`].join(`
|
|
440
440
|
`));this.vfs.writeFile(this.registryPath,`${t.join(`
|
|
441
441
|
|
|
442
442
|
`)}
|
|
443
443
|
`)}parseFields(t){let e={};for(let r of t.split(`
|
|
444
444
|
`)){let s=r.indexOf(": ");s!==-1&&(e[r.slice(0,s)]=r.slice(s+2))}return e}log(t){let r=`${new Date().toISOString().replace("T"," ").slice(0,19)} ${t}
|
|
445
445
|
`,s=this.vfs.exists(this.logPath)?this.vfs.readFile(this.logPath):"";this.vfs.writeFile(this.logPath,s+r)}aptLog(t,e){let r=new Date().toISOString(),s=this.vfs.exists(this.aptLogPath)?this.vfs.readFile(this.aptLogPath):"",i=[`Start-Date: ${r}`,`Commandline: apt-get ${t} ${e.join(" ")}`,`${t==="install"?"Install":"Remove"}: ${e.join(", ")}`,`End-Date: ${r}`,""].join(`
|
|
446
|
-
`);this.vfs.writeFile(this.aptLogPath,s+i)}findInRegistry(t){return
|
|
446
|
+
`);this.vfs.writeFile(this.aptLogPath,s+i)}findInRegistry(t){return dc.find(e=>e.name.toLowerCase()===t.toLowerCase())}listAvailable(){return[...dc].sort((t,e)=>t.name.localeCompare(e.name))}listInstalled(){return[...this.installed.values()].sort((t,e)=>t.name.localeCompare(e.name))}isInstalled(t){return this.installed.has(t.toLowerCase())}installedCount(){return this.installed.size}install(t,e={}){let r=[],s=[],i=[],o=(c,f=new Set)=>{if(f.has(c)||(f.add(c),this.isInstalled(c)))return;let l=this.findInRegistry(c);if(!l){i.push(c);return}for(let u of l.depends??[])o(u,f);s.find(u=>u.name===l.name)||s.push(l)};for(let c of t)o(c);if(i.length>0)return{output:`E: Unable to locate package ${i.join(", ")}`,exitCode:100};if(s.length===0)return{output:t.map(c=>`${c} is already the newest version.`).join(`
|
|
447
447
|
`),exitCode:0};let a=s.reduce((c,f)=>c+(f.installedSizeKb??0),0);e.quiet||r.push("Reading package lists... Done","Building dependency tree... Done","Reading state information... Done","The following NEW packages will be installed:",` ${s.map(c=>c.name).join(" ")}`,`0 upgraded, ${s.length} newly installed, 0 to remove and 0 not upgraded.`,`Need to get 0 B/${a} kB of archives.`,`After this operation, ${a} kB of additional disk space will be used.`,"");for(let c of s){e.quiet||(r.push(`Selecting previously unselected package ${c.name}.`),r.push("(Reading database ... 12345 files and directories currently installed.)"),r.push(`Preparing to unpack .../archives/${c.name}_${c.version}_amd64.deb ...`),r.push(`Unpacking ${c.name} (${c.version}) ...`));for(let l of c.files??[]){let u=l.path.slice(0,l.path.lastIndexOf("/"));u&&!this.vfs.exists(u)&&this.vfs.mkdir(u,493),this.vfs.writeFile(l.path,l.content,{mode:l.mode??420})}c.onInstall?.(this.vfs,this.users),e.quiet||r.push(`Setting up ${c.name} (${c.version}) ...`);let f=new Date().toISOString();this.installed.set(c.name,{name:c.name,version:c.version,architecture:c.architecture??"amd64",maintainer:c.maintainer??"Fortune Maintainers <pkg@fortune.local>",description:c.description,section:c.section??"misc",installedSizeKb:c.installedSizeKb??0,installedAt:f,files:(c.files??[]).map(l=>l.path)}),this.log(`install ${c.name} ${c.version}`)}return this.aptLog("install",s.map(c=>c.name)),this.persist(),e.quiet||r.push("Processing triggers for man-db (2.11.2-2) ..."),{output:r.join(`
|
|
448
448
|
`),exitCode:0}}remove(t,e={}){let r=[],s=[];for(let i of t){let o=this.installed.get(i.toLowerCase());o?s.push(o):r.push(`Package '${i}' is not installed, so not removed`)}if(s.length===0)return{output:r.join(`
|
|
449
449
|
`)||"Nothing to remove.",exitCode:0};e.quiet||r.push("Reading package lists... Done","Building dependency tree... Done","The following packages will be REMOVED:",` ${s.map(i=>i.name).join(" ")}`,`0 upgraded, 0 newly installed, ${s.length} to remove and 0 not upgraded.`);for(let i of s){e.quiet||r.push(`Removing ${i.name} (${i.version}) ...`);for(let a of i.files)if(!(!e.purge&&(a.startsWith("/etc/")||a.endsWith(".conf"))))try{this.vfs.exists(a)&&this.vfs.remove(a)}catch{}this.findInRegistry(i.name)?.onRemove?.(this.vfs),this.installed.delete(i.name),this.log(`remove ${i.name} ${i.version}`)}return this.aptLog("remove",s.map(i=>i.name)),this.persist(),{output:r.join(`
|
|
450
|
-
`),exitCode:0}}search(t){let e=t.toLowerCase();return
|
|
451
|
-
`)}};var
|
|
450
|
+
`),exitCode:0}}search(t){let e=t.toLowerCase();return dc.filter(r=>r.name.includes(e)||r.description.toLowerCase().includes(e)||(r.shortDesc??"").toLowerCase().includes(e)).sort((r,s)=>r.name.localeCompare(s.name))}show(t){let e=this.findInRegistry(t);if(!e)return null;let r=this.installed.get(t);return[`Package: ${e.name}`,`Version: ${e.version}`,`Architecture: ${e.architecture??"amd64"}`,`Maintainer: ${e.maintainer??"Fortune Maintainers <pkg@fortune.local>"}`,`Installed-Size: ${e.installedSizeKb??0}`,`Depends: ${(e.depends??[]).join(", ")||"(none)"}`,`Section: ${e.section??"misc"}`,"Priority: optional",`Description: ${e.description}`,`Status: ${r?"install ok installed":"install ok not-installed"}`].join(`
|
|
451
|
+
`)}};var Zn=require("node:crypto"),Ah=require("node:events"),Eh=Vt(require("node:path"),1);function zA(){let n=process.env.SSH_MIMIC_FAST_PASSWORD_HASH;return!!n&&!["0","false","no","off"].includes(n.toLowerCase())}var Rt=Xn("VirtualUserManager"),zs=class n extends Ah.EventEmitter{constructor(e,r=!0){super();this.vfs=e;this.autoSudoForNewUsers=r;Rt.mark("constructor")}vfs;autoSudoForNewUsers;static recordCache=new Map;static fastPasswordHash=zA();usersPath="/virtual-env-js/.auth/htpasswd";sudoersPath="/virtual-env-js/.auth/sudoers";quotasPath="/virtual-env-js/.auth/quotas";authDirPath="/virtual-env-js/.auth";users=new Map;sudoers=new Set;quotas=new Map;activeSessions=new Map;nextTty=0;async initialize(){Rt.mark("initialize"),this.loadFromVfs(),this.loadSudoersFromVfs(),this.loadQuotasFromVfs();let e=!1;this.users.has("root")||(this.users.set("root",this.createRecord("root","")),e=!0),this.sudoers.add("root"),e&&await this.persist(),this.emit("initialized")}async setQuotaBytes(e,r){if(Rt.mark("setQuotaBytes"),this.validateUsername(e),!this.users.has(e))throw new Error(`quota: user '${e}' does not exist`);if(!Number.isFinite(r)||r<0)throw new Error("quota: maxBytes must be a non-negative number");this.quotas.set(e,Math.floor(r)),await this.persist()}async clearQuota(e){Rt.mark("clearQuota"),this.validateUsername(e),this.quotas.delete(e),await this.persist()}getQuotaBytes(e){return Rt.mark("getQuotaBytes"),this.quotas.get(e)??null}getUsageBytes(e){Rt.mark("getUsageBytes");let r=`/home/${e}`;return this.vfs.exists(r)?this.vfs.getUsageBytes(r):0}assertWriteWithinQuota(e,r,s){Rt.mark("assertWriteWithinQuota");let i=this.quotas.get(e);if(i===void 0)return;let o=mh(r),a=mh(`/home/${e}`);if(!(o===a||o.startsWith(`${a}/`)))return;let f=this.getUsageBytes(e),l=0;if(this.vfs.exists(o)){let g=this.vfs.stat(o);g.type==="file"&&(l=g.size)}let u=Buffer.isBuffer(s)?s.length:Buffer.byteLength(s,"utf8"),h=f-l+u;if(h>i)throw new Error(`quota exceeded for '${e}': ${h}/${i} bytes`)}verifyPassword(e,r){Rt.mark("verifyPassword");let s=this.users.get(e);return s?this.hashPassword(r)===s.passwordHash:!1}async addUser(e,r){if(Rt.mark("addUser"),this.validateUsername(e),this.validatePassword(r),this.users.has(e))return;this.users.set(e,this.createRecord(e,r)),this.autoSudoForNewUsers&&this.sudoers.add(e);let s=`/home/${e}`;this.vfs.exists(s)||(this.vfs.mkdir(s,493),this.vfs.writeFile(`${s}/README.txt`,`Welcome to the virtual environment, ${e}`)),await this.persist(),this.emit("user:add",{username:e})}getPasswordHash(e){Rt.mark("getPasswordHash");let r=this.users.get(e);return r?r.passwordHash:null}async setPassword(e,r){if(Rt.mark("setPassword"),this.validateUsername(e),this.validatePassword(r),!this.users.has(e))throw new Error(`passwd: user '${e}' does not exist`);this.users.set(e,this.createRecord(e,r)),await this.persist()}async deleteUser(e){if(Rt.mark("deleteUser"),this.validateUsername(e),e==="root")throw new Error("deluser: cannot delete root");if(!this.users.delete(e))throw new Error(`deluser: user '${e}' does not exist`);this.sudoers.delete(e),this.emit("user:delete",{username:e}),await this.persist()}isSudoer(e){return Rt.mark("isSudoer"),this.sudoers.has(e)}async addSudoer(e){if(Rt.mark("addSudoer"),this.validateUsername(e),!this.users.has(e))throw new Error(`sudoers: user '${e}' does not exist`);this.sudoers.add(e),await this.persist()}async removeSudoer(e){if(Rt.mark("removeSudoer"),this.validateUsername(e),e==="root")throw new Error("sudoers: cannot remove root");this.sudoers.delete(e),await this.persist()}registerSession(e,r){Rt.mark("registerSession");let s={id:(0,Zn.randomUUID)(),username:e,tty:`pts/${this.nextTty++}`,remoteAddress:r,startedAt:new Date().toISOString()};return this.activeSessions.set(s.id,s),this.emit("session:register",{sessionId:s.id,username:e,remoteAddress:r}),s}unregisterSession(e){if(Rt.mark("unregisterSession"),!e)return;let r=this.activeSessions.get(e);this.activeSessions.delete(e),r&&this.emit("session:unregister",{sessionId:e,username:r.username}),this.activeSessions.delete(e)}updateSession(e,r,s){if(Rt.mark("updateSession"),!e)return;let i=this.activeSessions.get(e);i&&this.activeSessions.set(e,{...i,username:r,remoteAddress:s})}listActiveSessions(){return Rt.mark("listActiveSessions"),Array.from(this.activeSessions.values()).sort((e,r)=>e.startedAt.localeCompare(r.startedAt))}listUsers(){return Array.from(this.users.keys()).sort()}loadFromVfs(){if(this.users.clear(),!this.vfs.exists(this.usersPath))return;let e=this.vfs.readFile(this.usersPath);for(let r of e.split(`
|
|
452
452
|
`)){let s=r.trim();if(s.length===0)continue;let i=s.split(":");if(i.length<3)continue;let[o,a,c]=i;!o||!a||!c||this.users.set(o,{username:o,salt:a,passwordHash:c})}}loadSudoersFromVfs(){if(this.sudoers.clear(),!this.vfs.exists(this.sudoersPath))return;let e=this.vfs.readFile(this.sudoersPath);for(let r of e.split(`
|
|
453
453
|
`)){let s=r.trim();s.length>0&&this.sudoers.add(s)}}loadQuotasFromVfs(){if(this.quotas.clear(),!this.vfs.exists(this.quotasPath))return;let e=this.vfs.readFile(this.quotasPath);for(let r of e.split(`
|
|
454
454
|
`)){let s=r.trim();if(s.length===0)continue;let[i,o]=s.split(":"),a=Number.parseInt(o??"",10);!i||!Number.isFinite(a)||a<0||this.quotas.set(i,a)}}async persist(){this.vfs.exists(this.authDirPath)||this.vfs.mkdir(this.authDirPath,448);let e=Array.from(this.users.values()).sort((o,a)=>o.username.localeCompare(a.username)).map(o=>[o.username,o.salt,o.passwordHash].join(":")).join(`
|
|
@@ -457,21 +457,21 @@ echo 'journalctl: virtual stub'
|
|
|
457
457
|
`),i=!1;i=this.writeIfChanged(this.usersPath,e.length>0?`${e}
|
|
458
458
|
`:"",384)||i,i=this.writeIfChanged(this.sudoersPath,r.length>0?`${r}
|
|
459
459
|
`:"",384)||i,i=this.writeIfChanged(this.quotasPath,s.length>0?`${s}
|
|
460
|
-
`:"",384)||i,i&&await this.vfs.flushMirror()}writeIfChanged(e,r,s){return this.vfs.exists(e)&&this.vfs.readFile(e)===r?(this.vfs.chmod(e,s),!1):(this.vfs.writeFile(e,r,{mode:s}),!0)}createRecord(e,r){let s=`${e}:${r}`,i=n.recordCache.get(s);if(i)return i;let o=(0,
|
|
460
|
+
`:"",384)||i,i&&await this.vfs.flushMirror()}writeIfChanged(e,r,s){return this.vfs.exists(e)&&this.vfs.readFile(e)===r?(this.vfs.chmod(e,s),!1):(this.vfs.writeFile(e,r,{mode:s}),!0)}createRecord(e,r){let s=`${e}:${r}`,i=n.recordCache.get(s);if(i)return i;let o=(0,Zn.randomBytes)(16).toString("hex"),a={username:e,salt:o,passwordHash:this.hashPassword(r)};return n.recordCache.set(s,a),a}hasPassword(e){if(Rt.mark("hasPassword"),this.getPasswordHash(e)===this.hashPassword(""))return!1;let r=this.users.get(e);return!!r&&!!r.passwordHash}hashPassword(e){return n.fastPasswordHash?(0,Zn.createHash)("sha256").update(`${e}`).digest("hex"):(0,Zn.scryptSync)(e,"",32).toString("hex")}validateUsername(e){if(!e||e.trim()==="")throw new Error("invalid username");if(!/^[a-z_][a-z0-9_-]{0,31}$/i.test(e))throw new Error("invalid username")}validatePassword(e){if(!e||e.trim()==="")throw new Error("invalid password")}authorizedKeys=new Map;addAuthorizedKey(e,r,s){Rt.mark("addAuthorizedKey");let i=this.authorizedKeys.get(e)??[];i.push({algo:r,data:s}),this.authorizedKeys.set(e,i),this.emit("key:add",{username:e,algo:r})}removeAuthorizedKeys(e){this.authorizedKeys.delete(e),this.emit("key:remove",{username:e})}getAuthorizedKeys(e){return this.authorizedKeys.get(e)??[]}};function mh(n){let t=Eh.posix.normalize(n);return t.startsWith("/")?t:`/${t}`}var zr=require("node:fs/promises"),pc=Vt(require("node:path"),1);var wh=require("node:child_process");var _h=require("node:fs/promises"),js=Vt(require("node:path"),1);function hc(n){return`'${n.replace(/'/g,"'\\''")}'`}function Di(n){return n.replace(/\r\n/g,`
|
|
461
461
|
`).replace(/\r/g,`
|
|
462
462
|
`).replace(/\n/g,`\r
|
|
463
|
-
`)}function
|
|
463
|
+
`)}function yh(n,t){let e=Number.isFinite(t.cols)&&t.cols>0?Math.floor(t.cols):80,r=Number.isFinite(t.rows)&&t.rows>0?Math.floor(t.rows):24;return`stty cols ${e} rows ${r} 2>/dev/null; ${n}`}function bh(n,t){return!t||t.trim()===""||t==="."?n:t.startsWith("/")?js.posix.normalize(t):js.posix.normalize(js.posix.join(n,t))}async function xh(n){try{let e=(await(0,_h.readFile)(`/proc/${n}/task/${n}/children`,"utf8")).trim().split(/\s+/).filter(Boolean).map(s=>Number.parseInt(s,10)).filter(s=>Number.isInteger(s)&&s>0),r=await Promise.all(e.map(s=>xh(s)));return[...e,...r.flat()]}catch{return[]}}async function Sh(n=process.pid){let t=await xh(n),e=Array.from(new Set(t)).sort((r,s)=>r-s);return e.length===0?null:e.join(",")}function Ih(n,t,e){let r=yh(n,t),s=(0,wh.spawn)("script",["-qfec",r,"/dev/null"],{stdio:["pipe","pipe","pipe"],env:{...process.env,TERM:process.env.TERM??"xterm-256color"}});return s.stdout.on("data",i=>{e.write(i.toString("utf8"))}),s.stderr.on("data",i=>{e.write(i.toString("utf8"))}),s}function Ch(n,t,e){return Ih(`nano -- ${hc(n)}`,t,e)}function vh(n,t,e){return Ih(`htop -p ${hc(n)}`,t,e)}function kh(n,t,e){let r=n==="root",s=r?"\x1B[31;1m":"\x1B[35;1m",i="\x1B[37;1m",o="\x1B[34;1m",a="\x1B[0m";return`${i}[${s}${n}${i}@${o}${t}${a} ${e}${i}]${a}${r?"#":"$"} `}function Bh(n,t,e,r,s,i="unknown",o={cols:80,rows:24},a){let c="",f=0,l=jA(a.vfs),u=null,h="",g=`/home/${e}`,y=Kr(e,r),_=null,b=null,C=()=>{let v=`/home/${e}`,N=g===v?"~":pc.posix.basename(g)||"/";return kh(e,r,N)},L=Array.from(new Set(tc())).sort();console.log(`[${s}] Shell started for user '${e}' at ${i}`),(async()=>{let v=`/home/${e}/.bashrc`;if(a.vfs.exists(v))try{let N=a.vfs.readFile(v);for(let H of N.split(`
|
|
464
464
|
`)){let X=H.trim();!X||X.startsWith("#")||await Bt(X,e,r,"shell",g,a,void 0,y)}}catch{}})();function F(){let v=C();t.write(`\r${v}${c}\x1B[K`);let N=c.length-f;N>0&&t.write(`\x1B[${N}D`)}function k(){t.write("\r\x1B[K")}function K(v){b={...v,buffer:""},k(),t.write(v.prompt)}async function ee(v){if(!b)return;let N=b;if(b=null,!v){t.write(`\r
|
|
465
465
|
Sorry, try again.\r
|
|
466
466
|
`),F();return}if(!N.commandLine){e=N.targetUser,g=`/home/${e}`,a.users.updateSession(s,e,i),t.write(`\r
|
|
467
467
|
`),F();return}let H=N.loginShell?`/home/${N.targetUser}`:g,X=await Promise.resolve(Bt(N.commandLine,N.targetUser,r,"shell",H,a));if(t.write(`\r
|
|
468
|
-
`),X.openEditor){await x(X.openEditor.targetPath,X.openEditor.initialContent,X.openEditor.tempPath);return}if(X.openHtop){await w();return}X.clearScreen&&t.write("\x1B[2J\x1B[H"),X.stdout&&t.write(`${
|
|
469
|
-
`),X.stderr&&t.write(`${
|
|
470
|
-
`),X.switchUser?(e=X.switchUser,g=X.nextCwd??`/home/${e}`,a.users.updateSession(s,e,i)):X.nextCwd&&(g=X.nextCwd),await a.vfs.flushMirror(),F()}async function O(){if(!_)return;let v=_;if(v.kind==="nano"){try{let N=await(0,
|
|
471
|
-
`),F()}async function x(v,N,H){a.vfs.exists(v)&&await(0,
|
|
472
|
-
`),O()}),X.on("close",()=>{O()}),_={kind:"nano",targetPath:v,tempPath:H,process:X}}async function w(){let v=await
|
|
473
|
-
`);return}let N=
|
|
474
|
-
`),O()}),N.on("close",()=>{O()}),_={kind:"htop",targetPath:"",tempPath:"",process:N}}function I(v){c=v,f=c.length,F()}function U(v){c=`${c.slice(0,f)}${v}${c.slice(f)}`,f+=v.length,F()}function R(v,N){let H=N;for(;H>0&&!/\s/.test(v[H-1]);)H-=1;let X=N;for(;X<v.length&&!/\s/.test(v[X]);)X+=1;return{start:H,end:X}}function re(v){let N=v.lastIndexOf("/"),H=N>=0?v.slice(0,N+1):"",X=N>=0?v.slice(N+1):v,fe=
|
|
468
|
+
`),X.openEditor){await x(X.openEditor.targetPath,X.openEditor.initialContent,X.openEditor.tempPath);return}if(X.openHtop){await w();return}X.clearScreen&&t.write("\x1B[2J\x1B[H"),X.stdout&&t.write(`${Di(X.stdout)}\r
|
|
469
|
+
`),X.stderr&&t.write(`${Di(X.stderr)}\r
|
|
470
|
+
`),X.switchUser?(e=X.switchUser,g=X.nextCwd??`/home/${e}`,a.users.updateSession(s,e,i)):X.nextCwd&&(g=X.nextCwd),await a.vfs.flushMirror(),F()}async function O(){if(!_)return;let v=_;if(v.kind==="nano"){try{let N=await(0,zr.readFile)(v.tempPath,"utf8");a.writeFileAsUser(e,v.targetPath,N),await a.vfs.flushMirror()}catch{}await(0,zr.unlink)(v.tempPath).catch(()=>{})}_=null,c="",f=0,t.write(`\r
|
|
471
|
+
`),F()}async function x(v,N,H){a.vfs.exists(v)&&await(0,zr.writeFile)(H,N,"utf8");let X=Ch(H,o,t);X.on("error",fe=>{t.write(`nano: ${fe.message}\r
|
|
472
|
+
`),O()}),X.on("close",()=>{O()}),_={kind:"nano",targetPath:v,tempPath:H,process:X}}async function w(){let v=await Sh();if(!v){t.write(`htop: no child_process processes to display\r
|
|
473
|
+
`);return}let N=vh(v,o,t);N.on("error",H=>{t.write(`htop: ${H.message}\r
|
|
474
|
+
`),O()}),N.on("close",()=>{O()}),_={kind:"htop",targetPath:"",tempPath:"",process:N}}function I(v){c=v,f=c.length,F()}function U(v){c=`${c.slice(0,f)}${v}${c.slice(f)}`,f+=v.length,F()}function R(v,N){let H=N;for(;H>0&&!/\s/.test(v[H-1]);)H-=1;let X=N;for(;X<v.length&&!/\s/.test(v[X]);)X+=1;return{start:H,end:X}}function re(v){let N=v.lastIndexOf("/"),H=N>=0?v.slice(0,N+1):"",X=N>=0?v.slice(N+1):v,fe=bh(g,H||".");try{return a.vfs.list(fe).filter(se=>!se.startsWith(".")).filter(se=>se.startsWith(X)).map(se=>{let ze=pc.posix.join(fe,se),An=a.vfs.stat(ze).type==="directory"?"/":"";return`${H}${se}${An}`}).sort()}catch{return[]}}function G(){let{start:v,end:N}=R(c,f),H=c.slice(v,f);if(H.length===0)return;let fe=c.slice(0,v).trim().length===0?L.filter(_t=>_t.startsWith(H)):[],se=re(H),ze=Array.from(new Set([...fe,...se])).sort();if(ze.length!==0){if(ze.length===1){let _t=ze[0],An=_t.endsWith("/")?"":" ";c=`${c.slice(0,v)}${_t}${An}${c.slice(N)}`,f=v+_t.length+An.length,F();return}t.write(`\r
|
|
475
475
|
`),t.write(`${ze.join(" ")}\r
|
|
476
476
|
`),F()}}function Y(v){if(v.length===0)return;l.push(v),l.length>500&&(l=l.slice(l.length-500));let N=l.length>0?`${l.join(`
|
|
477
477
|
`)}
|
|
@@ -483,7 +483,7 @@ Sorry, try again.\r
|
|
|
483
483
|
`),t.write(`\r
|
|
484
484
|
`),t.write(`Fortune GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent\r
|
|
485
485
|
`),t.write(`permitted by applicable law.\r
|
|
486
|
-
`),v){let H=new Date(v.at),X=Number.isNaN(H.getTime())?v.at:
|
|
486
|
+
`),v){let H=new Date(v.at),X=Number.isNaN(H.getTime())?v.at:qs(H);t.write(`Last login: ${X} from ${v.from||"unknown"}\r
|
|
487
487
|
`)}t.write(`\r
|
|
488
488
|
`),ce(N)}D(),F(),t.on("data",async v=>{if(_){_.process.stdin.write(v);return}if(b){let H=v.toString("utf8");for(let X=0;X<H.length;X+=1){let fe=H[X];if(fe===""){b=null,t.write(`^C\r
|
|
489
489
|
`),F();return}if(fe==="\x7F"||fe==="\b"){b.buffer=b.buffer.slice(0,-1);continue}if(fe==="\r"||fe===`
|
|
@@ -492,16 +492,16 @@ Sorry, try again.\r
|
|
|
492
492
|
`),t.exit(0),t.end();return}if(X===" "){G();continue}if(X==="\x1B"){let fe=N[H+1],se=N[H+2],ze=N[H+3];if(fe==="["&&se){if(se==="A"){H+=2,l.length>0&&(u===null?(h=c,u=l.length-1):u>0&&(u-=1),I(l[u]??""));continue}if(se==="B"){H+=2,u!==null&&(u<l.length-1?(u+=1,I(l[u]??"")):(u=null,I(h)));continue}if(se==="C"){H+=2,f<c.length&&(f+=1,t.write("\x1B[C"));continue}if(se==="D"){H+=2,f>0&&(f-=1,t.write("\x1B[D"));continue}if(se==="3"&&ze==="~"){H+=3,f<c.length&&(c=`${c.slice(0,f)}${c.slice(f+1)}`,F());continue}}}if(X===""){c="",f=0,u=null,h="",t.write(`^C\r
|
|
493
493
|
`),F();continue}if(X==="\r"||X===`
|
|
494
494
|
`){let fe=c.trim();if(c="",f=0,u=null,h="",t.write(`\r
|
|
495
|
-
`),fe.length>0){let se=await Promise.resolve(Bt(fe,e,r,"shell",g,a,void 0,y));if(Y(fe),se.openEditor){await x(se.openEditor.targetPath,se.openEditor.initialContent,se.openEditor.tempPath);return}if(se.openHtop){await w();return}if(se.sudoChallenge){K(se.sudoChallenge);return}if(se.clearScreen&&t.write("\x1B[2J\x1B[H"),se.stdout&&t.write(`${
|
|
496
|
-
`),se.stderr&&t.write(`${
|
|
495
|
+
`),fe.length>0){let se=await Promise.resolve(Bt(fe,e,r,"shell",g,a,void 0,y));if(Y(fe),se.openEditor){await x(se.openEditor.targetPath,se.openEditor.initialContent,se.openEditor.tempPath);return}if(se.openHtop){await w();return}if(se.sudoChallenge){K(se.sudoChallenge);return}if(se.clearScreen&&t.write("\x1B[2J\x1B[H"),se.stdout&&t.write(`${Di(se.stdout)}\r
|
|
496
|
+
`),se.stderr&&t.write(`${Di(se.stderr)}\r
|
|
497
497
|
`),se.closeSession){t.write(`logout\r
|
|
498
|
-
`),t.exit(se.exitCode??0),t.end();return}se.nextCwd&&(g=se.nextCwd),se.switchUser&&(e=se.switchUser,g=se.nextCwd??`/home/${e}`,a.users.updateSession(s,e,i),c="",f=0),await a.vfs.flushMirror()}F();continue}if(X==="\x7F"||X==="\b"){f>0&&(c=`${c.slice(0,f-1)}${c.slice(f)}`,f-=1,F());continue}U(X)}}),t.on("close",()=>{_&&(_.process.kill("SIGTERM"),_=null)})}function
|
|
499
|
-
`).map(r=>r.trim()).filter(r=>r.length>0):(n.writeFile(t,""),[])}var
|
|
498
|
+
`),t.exit(se.exitCode??0),t.end();return}se.nextCwd&&(g=se.nextCwd),se.switchUser&&(e=se.switchUser,g=se.nextCwd??`/home/${e}`,a.users.updateSession(s,e,i),c="",f=0),await a.vfs.flushMirror()}F();continue}if(X==="\x7F"||X==="\b"){f>0&&(c=`${c.slice(0,f-1)}${c.slice(f)}`,f-=1,F());continue}U(X)}}),t.on("close",()=>{_&&(_.process.kill("SIGTERM"),_=null)})}function jA(n){let t="/virtual-env-js/.bash_history";return n.exists(t)?n.readFile(t).split(`
|
|
499
|
+
`).map(r=>r.trim()).filter(r=>r.length>0):(n.writeFile(t,""),[])}var XA={kernel:"1.0.0+itsrealfortune+1-amd64",os:"Fortune GNU/Linux x64",arch:"x86_64"},Oi=Xn("VirtualShell");function JA(){let n=process.env.SSH_MIMIC_AUTO_SUDO_NEW_USERS;return n?!["0","false","no","off"].includes(n.toLowerCase()):!0}var hr=class extends Rh.EventEmitter{vfs;users;packageManager;hostname;properties;startTime;initialized;constructor(t,e,r){super(),Oi.mark("constructor"),this.hostname=t,this.properties=e||XA,this.startTime=Date.now();function s(u){return typeof u=="object"&&u!==null&&"vfsInstance"in u&&u.vfsInstance instanceof uc}r&&s(r)?this.vfs=r.vfsInstance:this.vfs=new uc(r??{}),this.users=new zs(this.vfs,JA()),this.packageManager=new Ys(this.vfs,this.users);let i=this.vfs,o=this.users,a=this.packageManager,c=this.properties,f=this.hostname,l=this.startTime;this.initialized=(async()=>{await i.restoreMirror(),await o.initialize(),sh(i,o,f,c,l),a.load(),this.emit("initialized")})()}async ensureInitialized(){Oi.mark("ensureInitialized"),await this.initialized}addCommand(t,e,r){let s=t.trim().toLowerCase();if(s.length===0||/\s/.test(s))throw new Error("Command name must be non-empty and contain no spaces");Za(ec(s,e,r))}executeCommand(t,e,r){Oi.mark("executeCommand"),Bt(t,e,this.hostname,"shell",r,this),this.emit("command",{command:t,user:e,cwd:r})}startInteractiveSession(t,e,r,s,i){Oi.mark("startInteractiveSession"),this.emit("session:start",{user:e,sessionId:r,remoteAddress:s}),Bh(this.properties,t,e,this.hostname,r,s,i,this),this.refreshProcSessions()}refreshProcFs(){Vs(this.vfs,this.properties,this.hostname,this.startTime,this.users.listActiveSessions())}refreshProcSessions(){Vs(this.vfs,this.properties,this.hostname,this.startTime,this.users.listActiveSessions())}syncPasswd(){oc(this.vfs,this.users)}getVfs(){return this?.vfs??null}getUsers(){return this?.users??null}getHostname(){return this?.hostname}writeFileAsUser(t,e,r){Oi.mark("writeFileAsUser"),this.users.assertWriteWithinQuota(t,e,r),this.vfs.writeFile(e,r)}};function Nh(n){return n.replace(/\r\n/g,`
|
|
500
500
|
`).replace(/\r/g,`
|
|
501
501
|
`).replace(/\n/g,`\r
|
|
502
|
-
`)}function Ph(n,t,e,r,s){Promise.resolve(Bt(t,e,r,"exec",`/home/${e}`,s,void 0,
|
|
502
|
+
`)}function Ph(n,t,e,r,s){Promise.resolve(Bt(t,e,r,"exec",`/home/${e}`,s,void 0,Kr(e,r))).then(i=>{i.stdout&&n.write(`${Nh(i.stdout)}\r
|
|
503
503
|
`),i.stderr&&n.stderr.write(`${Nh(i.stderr)}\r
|
|
504
504
|
`),n.exit(i.exitCode??0),s.vfs.flushMirror(),n.end()}).catch(i=>{console.error("Exec error:",i),n.stderr.write(`Error: ${String(i)}\r
|
|
505
|
-
`),n.exit(1),n.end()})}var Th=require("node:crypto"),er=require("node:fs"),Xs=require("node:path");function
|
|
506
|
-
`),this.shell.vfs.flushMirror())}async start(){
|
|
505
|
+
`),n.exit(1),n.end()})}var Th=require("node:crypto"),er=require("node:fs"),Xs=require("node:path");function gc(n=process.cwd()){let t=(0,Xs.resolve)(n,".ssh-mimic","host_rsa");if((0,er.existsSync)(t))return(0,er.readFileSync)(t,"utf8");let e=(0,Th.generateKeyPairSync)("rsa",{modulusLength:2048,privateKeyEncoding:{type:"pkcs1",format:"pem"},publicKeyEncoding:{type:"pkcs1",format:"pem"}}).privateKey;return(0,er.mkdirSync)((0,Xs.dirname)(t),{recursive:!0}),(0,er.writeFileSync)(t,e,{mode:384}),e}var ZA=Vt(Va(),1);var uS=Xn("SftpMimic");var mc=Xn("SshMimic"),Js=class extends Lh.EventEmitter{port;server;shell;maxAuthAttempts;lockoutDurationMs;authAttempts=new Map;constructor({port:t,hostname:e="typescript-vm",shell:r=new hr(e),maxAuthAttempts:s=5,lockoutDurationMs:i=6e4}){super(),mc.mark("constructor"),this.port=t,this.server=null,this.shell=r,this.maxAuthAttempts=s,this.lockoutDurationMs=i}isLockedOut(t){let e=this.authAttempts.get(t);return e?Date.now()<e.lockedUntil?!0:(e.lockedUntil>0&&this.authAttempts.delete(t),!1):!1}recordFailure(t){let e=this.authAttempts.get(t)??{attempts:0,lockedUntil:0};e.attempts+=1,e.attempts>=this.maxAuthAttempts&&(e.lockedUntil=Date.now()+this.lockoutDurationMs,this.emit("auth:lockout",{ip:t,until:new Date(e.lockedUntil)})),this.authAttempts.set(t,e)}recordSuccess(t){this.authAttempts.delete(t)}ensureHomeDir(t){let e=`/home/${t}`;this.shell.vfs.exists(e)||(this.shell.vfs.mkdir(e,493),this.shell.vfs.writeFile(`${e}/README.txt`,`Welcome to ${this.shell.hostname}
|
|
506
|
+
`),this.shell.vfs.flushMirror())}async start(){mc.mark("start");let t=this.shell,e=gc();return await t.ensureInitialized(),this.server=new Uh.Server({hostKeys:[e],ident:`SSH-2.0-${t.hostname}`},r=>{let s="root",i="unknown",o=null;this.emit("client:connect"),r.on("authentication",a=>{let c=a.username||"root";if(i=a.ip??i,this.isLockedOut(i)){this.emit("auth:failure",{username:c,remoteAddress:i,reason:"lockout"}),a.reject();return}if(a.method==="password"){if(!t.users.hasPassword(c)){console.log(`User ${c} has no password set, allowing login without verification`),s=c,o=t.users.registerSession(s,i).id,this.recordSuccess(i),this.emit("auth:success",{username:s,remoteAddress:i}),this.ensureHomeDir(s),a.accept();return}if(!a.password||a.password===""||!t.users.verifyPassword(c,a.password)){this.recordFailure(i),this.emit("auth:failure",{username:c,remoteAddress:i}),a.reject();return}s=c,o=t.users.registerSession(s,i).id,this.recordSuccess(i),this.emit("auth:success",{username:s,remoteAddress:i}),this.ensureHomeDir(s),a.accept();return}if(a.method==="publickey"){let f=t.users.getAuthorizedKeys(c);if(f.length===0){a.reject();return}let l=a.key;if(!f.some(h=>h.algo===l.algo&&h.data.equals(l.data))){this.recordFailure(i),this.emit("auth:failure",{username:c,remoteAddress:i,method:"publickey"}),a.reject();return}a.signature&&(s=c,o=t.users.registerSession(s,i).id,this.recordSuccess(i),this.emit("auth:success",{username:s,remoteAddress:i,method:"publickey"}),this.ensureHomeDir(s)),a.accept();return}a.reject(["password","publickey"])}),r.on("close",()=>{t.users.unregisterSession(o),this.emit("client:disconnect",{user:s}),o=null}),r.on("ready",()=>{r.on("session",a=>{let c=a(),f={cols:80,rows:24};c.on("pty",(l,u,h)=>{f.cols=h?.cols??f.cols,f.rows=h?.rows??f.rows,l()}),c.on("window-change",(l,u,h)=>{f.cols=h?.cols??f.cols,f.rows=h?.rows??f.rows}),c.on("shell",l=>{let u=l();t?.startInteractiveSession(u,s,o,i,f)}),c.on("exec",(l,u,h)=>{let g=l();g&&Ph(g,h.command.trim(),s,t.hostname,t)})})})}),new Promise((r,s)=>{this.server?.once("error",i=>s(i)),this.server?.listen(this.port,"0.0.0.0",()=>{console.log(`SSH Mimic listening on port ${this.port}`),this.emit("start",{port:this.port}),r(this.port)})})}stop(){mc.mark("stop"),this.server&&this.server.close(()=>{console.log("SSH Mimic stopped"),this.emit("stop")})}clearLockout(t){this.authAttempts.delete(t)}};var Dh=process.env.SSH_MIMIC_HOSTNAME??"typescript-vm",Oh=new hr(Dh,void 0,{mode:"fs",snapshotPath:".vfs"});Oh.addCommand("demo",[],()=>({stdout:"This is a demo command. It does nothing useful.",exitCode:0}));new Js({port:2222,hostname:Dh,shell:Oh}).start().catch(n=>{console.error("Failed to start SSH Mimic:",n),process.exit(1)});process.on("uncaughtException",n=>{console.log("Oh my god, something terrible happened: ",n)});process.on("unhandledRejection",(n,t)=>{console.log(" Oh Lord! We forgot to handle a promise rejection here: ",t),console.log(" The error was: ",n)});
|
|
507
507
|
//# sourceMappingURL=standalone-wo-sftp.js.map
|