typescript-virtual-container 1.4.9 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/.vscode/settings.json +1 -1
  2. package/README.md +141 -89
  3. package/builds/fortune-nyx-v1.5.1-directbash-k6.1.0.mjs +1768 -0
  4. package/builds/fortune-nyx-v1.5.1-ssh-nosftp.js +1768 -0
  5. package/builds/fortune-nyx-v1.5.1-ssh.cjs +1769 -0
  6. package/bun.lock +3 -3
  7. package/dist/SSHMimic/exec.js +2 -2
  8. package/dist/SSHMimic/exec.js.map +1 -1
  9. package/dist/SSHMimic/index.d.ts.map +1 -1
  10. package/dist/SSHMimic/index.js +2 -1
  11. package/dist/SSHMimic/index.js.map +1 -1
  12. package/dist/SSHMimic/sftp.d.ts.map +1 -1
  13. package/dist/SSHMimic/sftp.js +4 -3
  14. package/dist/SSHMimic/sftp.js.map +1 -1
  15. package/dist/VirtualFileSystem/index.d.ts +14 -0
  16. package/dist/VirtualFileSystem/index.d.ts.map +1 -1
  17. package/dist/VirtualFileSystem/index.js +51 -3
  18. package/dist/VirtualFileSystem/index.js.map +1 -1
  19. package/dist/VirtualFileSystem/journal.d.ts.map +1 -1
  20. package/dist/VirtualFileSystem/journal.js +13 -5
  21. package/dist/VirtualFileSystem/journal.js.map +1 -1
  22. package/dist/VirtualShell/shell.js +12 -12
  23. package/dist/VirtualShell/shell.js.map +1 -1
  24. package/dist/VirtualUserManager/index.js +8 -11
  25. package/dist/VirtualUserManager/index.js.map +1 -1
  26. package/dist/commands/apt.js +3 -3
  27. package/dist/commands/apt.js.map +1 -1
  28. package/dist/commands/cd.d.ts.map +1 -1
  29. package/dist/commands/cd.js +2 -1
  30. package/dist/commands/cd.js.map +1 -1
  31. package/dist/commands/helpers.d.ts +1 -1
  32. package/dist/commands/helpers.d.ts.map +1 -1
  33. package/dist/commands/helpers.js +3 -2
  34. package/dist/commands/helpers.js.map +1 -1
  35. package/dist/commands/index.d.ts +1 -1
  36. package/dist/commands/index.d.ts.map +1 -1
  37. package/dist/commands/index.js +1 -1
  38. package/dist/commands/index.js.map +1 -1
  39. package/dist/commands/lsb-release.js +1 -1
  40. package/dist/commands/lsb-release.js.map +1 -1
  41. package/dist/commands/runtime.d.ts +2 -0
  42. package/dist/commands/runtime.d.ts.map +1 -1
  43. package/dist/commands/runtime.js +5 -1
  44. package/dist/commands/runtime.js.map +1 -1
  45. package/dist/modules/linuxRootfs.d.ts +9 -5
  46. package/dist/modules/linuxRootfs.d.ts.map +1 -1
  47. package/dist/modules/linuxRootfs.js +1079 -148
  48. package/dist/modules/linuxRootfs.js.map +1 -1
  49. package/dist/self-standalone.js +22 -12
  50. package/dist/self-standalone.js.map +1 -1
  51. package/docs/assets/hierarchy.js +1 -1
  52. package/docs/classes/HoneyPot.html +9 -9
  53. package/docs/classes/IdleManager.html +8 -8
  54. package/docs/classes/SshClient.html +18 -18
  55. package/docs/classes/VirtualFileSystem.html +34 -34
  56. package/docs/classes/VirtualPackageManager.html +13 -13
  57. package/docs/classes/VirtualSftpServer.html +3 -3
  58. package/docs/classes/VirtualShell.html +28 -28
  59. package/docs/classes/VirtualSshServer.html +5 -5
  60. package/docs/classes/VirtualUserManager.html +27 -27
  61. package/docs/functions/assertDiff.html +2 -2
  62. package/docs/functions/diffSnapshots.html +2 -2
  63. package/docs/functions/formatDiff.html +2 -2
  64. package/docs/functions/getArg.html +2 -2
  65. package/docs/functions/getFlag.html +2 -2
  66. package/docs/functions/ifFlag.html +2 -2
  67. package/docs/hierarchy.html +1 -1
  68. package/docs/index.html +37 -31
  69. package/docs/interfaces/AuditLogEntry.html +3 -3
  70. package/docs/interfaces/CommandContext.html +12 -12
  71. package/docs/interfaces/CommandResult.html +13 -13
  72. package/docs/interfaces/ExecStream.html +6 -6
  73. package/docs/interfaces/HoneyPotStats.html +3 -3
  74. package/docs/interfaces/IdleManagerOptions.html +3 -3
  75. package/docs/interfaces/InstalledPackage.html +11 -11
  76. package/docs/interfaces/NanoEditorSession.html +5 -5
  77. package/docs/interfaces/PackageDefinition.html +14 -14
  78. package/docs/interfaces/PackageFile.html +5 -5
  79. package/docs/interfaces/PasswordChallenge.html +9 -9
  80. package/docs/interfaces/RemoveOptions.html +3 -3
  81. package/docs/interfaces/ShellEnv.html +4 -4
  82. package/docs/interfaces/ShellModule.html +8 -8
  83. package/docs/interfaces/ShellProperties.html +5 -5
  84. package/docs/interfaces/ShellStream.html +7 -7
  85. package/docs/interfaces/SudoChallenge.html +9 -9
  86. package/docs/interfaces/VfsBaseNode.html +7 -7
  87. package/docs/interfaces/VfsDiff.html +6 -6
  88. package/docs/interfaces/VfsDiffEntry.html +4 -4
  89. package/docs/interfaces/VfsDiffModified.html +6 -6
  90. package/docs/interfaces/VfsDirectoryNode.html +8 -8
  91. package/docs/interfaces/VfsFileNode.html +9 -9
  92. package/docs/interfaces/VfsOptions.html +6 -6
  93. package/docs/interfaces/VfsSnapshot.html +3 -3
  94. package/docs/interfaces/VfsSnapshotBaseNode.html +4 -4
  95. package/docs/interfaces/VfsSnapshotDirectoryNode.html +5 -5
  96. package/docs/interfaces/VfsSnapshotFileNode.html +6 -6
  97. package/docs/interfaces/VirtualActiveSession.html +7 -7
  98. package/docs/interfaces/VirtualSftpServerOptions.html +3 -3
  99. package/docs/interfaces/VirtualShellVfsLike.html +3 -3
  100. package/docs/interfaces/VirtualShellVfsOptions.html +3 -3
  101. package/docs/interfaces/WriteFileOptions.html +4 -4
  102. package/docs/modules.html +1 -1
  103. package/docs/types/ArgParseOptions.html +3 -3
  104. package/docs/types/CommandMode.html +2 -2
  105. package/docs/types/CommandOutcome.html +2 -2
  106. package/docs/types/IdleState.html +1 -1
  107. package/docs/types/VfsNodeStats.html +2 -2
  108. package/docs/types/VfsNodeType.html +2 -2
  109. package/docs/types/VfsPersistenceMode.html +2 -2
  110. package/docs/types/VfsSnapshotNode.html +2 -2
  111. package/package.json +6 -5
  112. package/scripts/build-all.mjs +198 -0
  113. package/scripts/build-names.mjs +44 -0
  114. package/src/SSHMimic/exec.ts +2 -2
  115. package/src/SSHMimic/index.ts +2 -1
  116. package/src/SSHMimic/sftp.ts +4 -3
  117. package/src/VirtualFileSystem/index.ts +46 -3
  118. package/src/VirtualFileSystem/journal.ts +12 -5
  119. package/src/VirtualShell/shell.ts +12 -12
  120. package/src/VirtualUserManager/index.ts +11 -11
  121. package/src/commands/apt.ts +3 -3
  122. package/src/commands/cd.ts +2 -1
  123. package/src/commands/helpers.ts +3 -2
  124. package/src/commands/index.ts +1 -1
  125. package/src/commands/lsb-release.ts +1 -1
  126. package/src/commands/runtime.ts +6 -1
  127. package/src/modules/linuxRootfs.ts +1293 -207
  128. package/src/self-standalone.ts +26 -12
  129. package/tests/new-features.test.ts +2 -2
  130. package/tests/sftp.test.ts +13 -13
  131. package/builds/self-standalone.js +0 -1299
  132. package/builds/standalone-wo-sftp.js +0 -1300
  133. package/builds/standalone.cjs +0 -1301
  134. /package/builds/{web-full-api.min.js → fortune-nyx-v1.5.1-web-full.min.js} +0 -0
  135. /package/builds/{web.min.js → fortune-nyx-v1.5.1-web.min.js} +0 -0
@@ -1,1301 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";var xp=Object.create;var Vc=Object.defineProperty;var wp=Object.getOwnPropertyDescriptor;var Ip=Object.getOwnPropertyNames;var Cp=Object.getPrototypeOf,vp=Object.prototype.hasOwnProperty;var lt=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports);var kp=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Ip(t))!vp.call(n,s)&&s!==e&&Vc(n,s,{get:()=>t[s],enumerable:!(r=wp(t,s))||r.enumerable});return n};var Wt=(n,t,e)=>(e=n!=null?xp(Cp(n)):{},kp(t||!n||!n.__esModule?Vc(e,"default",{value:n,enumerable:!0}):e,n));var Ss=lt((px,au)=>{au.exports={newInvalidAsn1Error:function(n){var t=new Error;return t.name="InvalidAsn1Error",t.message=n||"",t}}});var bs=lt((mx,cu)=>{cu.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 Uo=lt((gx,lu)=>{"use strict";var xs=require("buffer"),Mr=xs.Buffer,gn={},An;for(An in xs)xs.hasOwnProperty(An)&&(An==="SlowBuffer"||An==="Buffer"||(gn[An]=xs[An]));var Ur=gn.Buffer={};for(An in Mr)Mr.hasOwnProperty(An)&&(An==="allocUnsafe"||An==="allocUnsafeSlow"||(Ur[An]=Mr[An]));gn.Buffer.prototype=Mr.prototype;(!Ur.from||Ur.from===Uint8Array.from)&&(Ur.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 Mr(n,t,e)});Ur.alloc||(Ur.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=Mr(n);return!t||t.length===0?r.fill(0):typeof e=="string"?r.fill(t,e):r.fill(t),r});if(!gn.kStringMaxLength)try{gn.kStringMaxLength=process.binding("buffer").kStringMaxLength}catch{}gn.constants||(gn.constants={MAX_LENGTH:gn.kMaxLength},gn.kStringMaxLength&&(gn.constants.MAX_STRING_LENGTH=gn.kStringMaxLength));lu.exports=gn});var du=lt((Ax,uu)=>{var Mm=require("assert"),fu=Uo().Buffer,_i=bs(),Um=Ss(),$r=Um.newInvalidAsn1Error;function en(n){if(!n||!fu.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(en.prototype,"length",{enumerable:!0,get:function(){return this._len}});Object.defineProperty(en.prototype,"offset",{enumerable:!0,get:function(){return this._offset}});Object.defineProperty(en.prototype,"remain",{get:function(){return this._size-this._offset}});Object.defineProperty(en.prototype,"buffer",{get:function(){return this._buf.slice(this._offset)}});en.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};en.prototype.peek=function(){return this.readByte(!0)};en.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 $r("Indefinite length not supported");if(t>4)throw $r("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};en.prototype.readSequence=function(n){var t=this.peek();if(t===null)return null;if(n!==void 0&&n!==t)throw $r("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)};en.prototype.readInt=function(){return this._readTag(_i.Integer)};en.prototype.readBoolean=function(){return this._readTag(_i.Boolean)!==0};en.prototype.readEnumeration=function(){return this._readTag(_i.Enumeration)};en.prototype.readString=function(n,t){n||(n=_i.OctetString);var e=this.peek();if(e===null)return null;if(e!==n)throw $r("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?fu.alloc(0):"";var s=this._buf.slice(this._offset,this._offset+this.length);return this._offset+=this.length,t?s:s.toString("utf8")};en.prototype.readOID=function(n){n||(n=_i.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(".")};en.prototype._readTag=function(n){Mm.ok(n!==void 0);var t=this.peek();if(t===null)return null;if(t!==n)throw $r("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 $r("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};uu.exports=en});var pu=lt((Ex,hu)=>{var jn=require("assert"),ws=Uo().Buffer,Xn=bs(),$m=Ss(),Is=$m.newInvalidAsn1Error,Fm={size:1024,growthFactor:8};function Hm(n,t){jn.ok(n),jn.equal(typeof n,"object"),jn.ok(t),jn.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 jt(n){n=Hm(Fm,n||{}),this._buf=ws.alloc(n.size||1024),this._size=this._buf.length,this._offset=0,this._options=n,this._seq=[]}Object.defineProperty(jt.prototype,"buffer",{get:function(){if(this._seq.length)throw Is(this._seq.length+" unended sequence(s)");return this._buf.slice(0,this._offset)}});jt.prototype.writeByte=function(n){if(typeof n!="number")throw new TypeError("argument must be a Number");this._ensure(1),this._buf[this._offset++]=n};jt.prototype.writeInt=function(n,t){if(typeof n!="number")throw new TypeError("argument must be a Number");typeof t!="number"&&(t=Xn.Integer);for(var e=4;((n&4286578688)===0||(n&4286578688)===-8388608)&&e>1;)e--,n<<=8;if(e>4)throw Is("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};jt.prototype.writeNull=function(){this.writeByte(Xn.Null),this.writeByte(0)};jt.prototype.writeEnumeration=function(n,t){if(typeof n!="number")throw new TypeError("argument must be a Number");return typeof t!="number"&&(t=Xn.Enumeration),this.writeInt(n,t)};jt.prototype.writeBoolean=function(n,t){if(typeof n!="boolean")throw new TypeError("argument must be a Boolean");typeof t!="number"&&(t=Xn.Boolean),this._ensure(3),this._buf[this._offset++]=t,this._buf[this._offset++]=1,this._buf[this._offset++]=n?255:0};jt.prototype.writeString=function(n,t){if(typeof n!="string")throw new TypeError("argument must be a string (was: "+typeof n+")");typeof t!="number"&&(t=Xn.OctetString);var e=ws.byteLength(n);this.writeByte(t),this.writeLength(e),e&&(this._ensure(e),this._buf.write(n,this._offset),this._offset+=e)};jt.prototype.writeBuffer=function(n,t){if(typeof t!="number")throw new TypeError("tag must be a number");if(!ws.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};jt.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)})};jt.prototype.writeOID=function(n,t){if(typeof n!="string")throw new TypeError("argument must be a string");if(typeof t!="number"&&(t=Xn.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)})};jt.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 Is("Length too long (> 4 bytes)")};jt.prototype.startSequence=function(n){typeof n!="number"&&(n=Xn.Sequence|Xn.Constructor),this.writeByte(n),this._seq.push(this._offset),this._ensure(3),this._offset+=3};jt.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 Is("Sequence too long")};jt.prototype._shift=function(n,t,e){jn.ok(n!==void 0),jn.ok(t!==void 0),jn.ok(e),this._buf.copy(this._buf,n+e,n,n+t),this._offset+=e};jt.prototype._ensure=function(n){if(jn.ok(n),this._size-this._offset<n){var t=this._size*this._options.growthFactor;t-this._offset<n&&(t+=n);var e=ws.alloc(t);this._buf.copy(e,0,0,this._offset),this._buf=e,this._size=t}};hu.exports=jt});var mu=lt((yx,ks)=>{var $o=Ss(),Fo=bs(),Qm=du(),Wm=pu();ks.exports={Reader:Qm,Writer:Wm};for(Cs in Fo)Fo.hasOwnProperty(Cs)&&(ks.exports[Cs]=Fo[Cs]);var Cs;for(vs in $o)$o.hasOwnProperty(vs)&&(ks.exports[vs]=$o[vs]);var vs});var Si=lt((_x,gu)=>{var Ho=mu();gu.exports={Ber:Ho,BerReader:Ho.Reader,BerWriter:Ho.Writer}});var Au=lt((Sx,Ns)=>{(function(n){"use strict";var t=function(m){var E,g=new Float64Array(16);if(m)for(E=0;E<m.length;E++)g[E]=m[E];return g},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]),l=t([61785,9906,39828,60374,45398,33411,5274,224,53552,61171,33010,6542,64743,22239,55772,9222]),f=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 p(m,E,g,d){m[E]=g>>24&255,m[E+1]=g>>16&255,m[E+2]=g>>8&255,m[E+3]=g&255,m[E+4]=d>>24&255,m[E+5]=d>>16&255,m[E+6]=d>>8&255,m[E+7]=d&255}function A(m,E,g,d,_){var L,F=0;for(L=0;L<_;L++)F|=m[E+L]^g[d+L];return(1&F-1>>>8)-1}function y(m,E,g,d){return A(m,E,g,d,16)}function b(m,E,g,d){return A(m,E,g,d,32)}function x(m,E,g,d){for(var _=d[0]&255|(d[1]&255)<<8|(d[2]&255)<<16|(d[3]&255)<<24,L=g[0]&255|(g[1]&255)<<8|(g[2]&255)<<16|(g[3]&255)<<24,F=g[4]&255|(g[5]&255)<<8|(g[6]&255)<<16|(g[7]&255)<<24,J=g[8]&255|(g[9]&255)<<8|(g[10]&255)<<16|(g[11]&255)<<24,ae=g[12]&255|(g[13]&255)<<8|(g[14]&255)<<16|(g[15]&255)<<24,Ee=d[4]&255|(d[5]&255)<<8|(d[6]&255)<<16|(d[7]&255)<<24,me=E[0]&255|(E[1]&255)<<8|(E[2]&255)<<16|(E[3]&255)<<24,it=E[4]&255|(E[5]&255)<<8|(E[6]&255)<<16|(E[7]&255)<<24,Ae=E[8]&255|(E[9]&255)<<8|(E[10]&255)<<16|(E[11]&255)<<24,Oe=E[12]&255|(E[13]&255)<<8|(E[14]&255)<<16|(E[15]&255)<<24,Le=d[8]&255|(d[9]&255)<<8|(d[10]&255)<<16|(d[11]&255)<<24,Qe=g[16]&255|(g[17]&255)<<8|(g[18]&255)<<16|(g[19]&255)<<24,Fe=g[20]&255|(g[21]&255)<<8|(g[22]&255)<<16|(g[23]&255)<<24,De=g[24]&255|(g[25]&255)<<8|(g[26]&255)<<16|(g[27]&255)<<24,Ue=g[28]&255|(g[29]&255)<<8|(g[30]&255)<<16|(g[31]&255)<<24,Me=d[12]&255|(d[13]&255)<<8|(d[14]&255)<<16|(d[15]&255)<<24,ye=_,be=L,ge=F,_e=J,Se=ae,pe=Ee,W=me,q=it,re=Ae,X=Oe,Z=Le,oe=Qe,ve=Fe,We=De,Ke=Ue,qe=Me,I,ze=0;ze<20;ze+=2)I=ye+ve|0,Se^=I<<7|I>>>25,I=Se+ye|0,re^=I<<9|I>>>23,I=re+Se|0,ve^=I<<13|I>>>19,I=ve+re|0,ye^=I<<18|I>>>14,I=pe+be|0,X^=I<<7|I>>>25,I=X+pe|0,We^=I<<9|I>>>23,I=We+X|0,be^=I<<13|I>>>19,I=be+We|0,pe^=I<<18|I>>>14,I=Z+W|0,Ke^=I<<7|I>>>25,I=Ke+Z|0,ge^=I<<9|I>>>23,I=ge+Ke|0,W^=I<<13|I>>>19,I=W+ge|0,Z^=I<<18|I>>>14,I=qe+oe|0,_e^=I<<7|I>>>25,I=_e+qe|0,q^=I<<9|I>>>23,I=q+_e|0,oe^=I<<13|I>>>19,I=oe+q|0,qe^=I<<18|I>>>14,I=ye+_e|0,be^=I<<7|I>>>25,I=be+ye|0,ge^=I<<9|I>>>23,I=ge+be|0,_e^=I<<13|I>>>19,I=_e+ge|0,ye^=I<<18|I>>>14,I=pe+Se|0,W^=I<<7|I>>>25,I=W+pe|0,q^=I<<9|I>>>23,I=q+W|0,Se^=I<<13|I>>>19,I=Se+q|0,pe^=I<<18|I>>>14,I=Z+X|0,oe^=I<<7|I>>>25,I=oe+Z|0,re^=I<<9|I>>>23,I=re+oe|0,X^=I<<13|I>>>19,I=X+re|0,Z^=I<<18|I>>>14,I=qe+Ke|0,ve^=I<<7|I>>>25,I=ve+qe|0,We^=I<<9|I>>>23,I=We+ve|0,Ke^=I<<13|I>>>19,I=Ke+We|0,qe^=I<<18|I>>>14;ye=ye+_|0,be=be+L|0,ge=ge+F|0,_e=_e+J|0,Se=Se+ae|0,pe=pe+Ee|0,W=W+me|0,q=q+it|0,re=re+Ae|0,X=X+Oe|0,Z=Z+Le|0,oe=oe+Qe|0,ve=ve+Fe|0,We=We+De|0,Ke=Ke+Ue|0,qe=qe+Me|0,m[0]=ye>>>0&255,m[1]=ye>>>8&255,m[2]=ye>>>16&255,m[3]=ye>>>24&255,m[4]=be>>>0&255,m[5]=be>>>8&255,m[6]=be>>>16&255,m[7]=be>>>24&255,m[8]=ge>>>0&255,m[9]=ge>>>8&255,m[10]=ge>>>16&255,m[11]=ge>>>24&255,m[12]=_e>>>0&255,m[13]=_e>>>8&255,m[14]=_e>>>16&255,m[15]=_e>>>24&255,m[16]=Se>>>0&255,m[17]=Se>>>8&255,m[18]=Se>>>16&255,m[19]=Se>>>24&255,m[20]=pe>>>0&255,m[21]=pe>>>8&255,m[22]=pe>>>16&255,m[23]=pe>>>24&255,m[24]=W>>>0&255,m[25]=W>>>8&255,m[26]=W>>>16&255,m[27]=W>>>24&255,m[28]=q>>>0&255,m[29]=q>>>8&255,m[30]=q>>>16&255,m[31]=q>>>24&255,m[32]=re>>>0&255,m[33]=re>>>8&255,m[34]=re>>>16&255,m[35]=re>>>24&255,m[36]=X>>>0&255,m[37]=X>>>8&255,m[38]=X>>>16&255,m[39]=X>>>24&255,m[40]=Z>>>0&255,m[41]=Z>>>8&255,m[42]=Z>>>16&255,m[43]=Z>>>24&255,m[44]=oe>>>0&255,m[45]=oe>>>8&255,m[46]=oe>>>16&255,m[47]=oe>>>24&255,m[48]=ve>>>0&255,m[49]=ve>>>8&255,m[50]=ve>>>16&255,m[51]=ve>>>24&255,m[52]=We>>>0&255,m[53]=We>>>8&255,m[54]=We>>>16&255,m[55]=We>>>24&255,m[56]=Ke>>>0&255,m[57]=Ke>>>8&255,m[58]=Ke>>>16&255,m[59]=Ke>>>24&255,m[60]=qe>>>0&255,m[61]=qe>>>8&255,m[62]=qe>>>16&255,m[63]=qe>>>24&255}function B(m,E,g,d){for(var _=d[0]&255|(d[1]&255)<<8|(d[2]&255)<<16|(d[3]&255)<<24,L=g[0]&255|(g[1]&255)<<8|(g[2]&255)<<16|(g[3]&255)<<24,F=g[4]&255|(g[5]&255)<<8|(g[6]&255)<<16|(g[7]&255)<<24,J=g[8]&255|(g[9]&255)<<8|(g[10]&255)<<16|(g[11]&255)<<24,ae=g[12]&255|(g[13]&255)<<8|(g[14]&255)<<16|(g[15]&255)<<24,Ee=d[4]&255|(d[5]&255)<<8|(d[6]&255)<<16|(d[7]&255)<<24,me=E[0]&255|(E[1]&255)<<8|(E[2]&255)<<16|(E[3]&255)<<24,it=E[4]&255|(E[5]&255)<<8|(E[6]&255)<<16|(E[7]&255)<<24,Ae=E[8]&255|(E[9]&255)<<8|(E[10]&255)<<16|(E[11]&255)<<24,Oe=E[12]&255|(E[13]&255)<<8|(E[14]&255)<<16|(E[15]&255)<<24,Le=d[8]&255|(d[9]&255)<<8|(d[10]&255)<<16|(d[11]&255)<<24,Qe=g[16]&255|(g[17]&255)<<8|(g[18]&255)<<16|(g[19]&255)<<24,Fe=g[20]&255|(g[21]&255)<<8|(g[22]&255)<<16|(g[23]&255)<<24,De=g[24]&255|(g[25]&255)<<8|(g[26]&255)<<16|(g[27]&255)<<24,Ue=g[28]&255|(g[29]&255)<<8|(g[30]&255)<<16|(g[31]&255)<<24,Me=d[12]&255|(d[13]&255)<<8|(d[14]&255)<<16|(d[15]&255)<<24,ye=_,be=L,ge=F,_e=J,Se=ae,pe=Ee,W=me,q=it,re=Ae,X=Oe,Z=Le,oe=Qe,ve=Fe,We=De,Ke=Ue,qe=Me,I,ze=0;ze<20;ze+=2)I=ye+ve|0,Se^=I<<7|I>>>25,I=Se+ye|0,re^=I<<9|I>>>23,I=re+Se|0,ve^=I<<13|I>>>19,I=ve+re|0,ye^=I<<18|I>>>14,I=pe+be|0,X^=I<<7|I>>>25,I=X+pe|0,We^=I<<9|I>>>23,I=We+X|0,be^=I<<13|I>>>19,I=be+We|0,pe^=I<<18|I>>>14,I=Z+W|0,Ke^=I<<7|I>>>25,I=Ke+Z|0,ge^=I<<9|I>>>23,I=ge+Ke|0,W^=I<<13|I>>>19,I=W+ge|0,Z^=I<<18|I>>>14,I=qe+oe|0,_e^=I<<7|I>>>25,I=_e+qe|0,q^=I<<9|I>>>23,I=q+_e|0,oe^=I<<13|I>>>19,I=oe+q|0,qe^=I<<18|I>>>14,I=ye+_e|0,be^=I<<7|I>>>25,I=be+ye|0,ge^=I<<9|I>>>23,I=ge+be|0,_e^=I<<13|I>>>19,I=_e+ge|0,ye^=I<<18|I>>>14,I=pe+Se|0,W^=I<<7|I>>>25,I=W+pe|0,q^=I<<9|I>>>23,I=q+W|0,Se^=I<<13|I>>>19,I=Se+q|0,pe^=I<<18|I>>>14,I=Z+X|0,oe^=I<<7|I>>>25,I=oe+Z|0,re^=I<<9|I>>>23,I=re+oe|0,X^=I<<13|I>>>19,I=X+re|0,Z^=I<<18|I>>>14,I=qe+Ke|0,ve^=I<<7|I>>>25,I=ve+qe|0,We^=I<<9|I>>>23,I=We+ve|0,Ke^=I<<13|I>>>19,I=Ke+We|0,qe^=I<<18|I>>>14;m[0]=ye>>>0&255,m[1]=ye>>>8&255,m[2]=ye>>>16&255,m[3]=ye>>>24&255,m[4]=pe>>>0&255,m[5]=pe>>>8&255,m[6]=pe>>>16&255,m[7]=pe>>>24&255,m[8]=Z>>>0&255,m[9]=Z>>>8&255,m[10]=Z>>>16&255,m[11]=Z>>>24&255,m[12]=qe>>>0&255,m[13]=qe>>>8&255,m[14]=qe>>>16&255,m[15]=qe>>>24&255,m[16]=W>>>0&255,m[17]=W>>>8&255,m[18]=W>>>16&255,m[19]=W>>>24&255,m[20]=q>>>0&255,m[21]=q>>>8&255,m[22]=q>>>16&255,m[23]=q>>>24&255,m[24]=re>>>0&255,m[25]=re>>>8&255,m[26]=re>>>16&255,m[27]=re>>>24&255,m[28]=X>>>0&255,m[29]=X>>>8&255,m[30]=X>>>16&255,m[31]=X>>>24&255}function H(m,E,g,d){x(m,E,g,d)}function C(m,E,g,d){B(m,E,g,d)}var M=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function Q(m,E,g,d,_,L,F){var J=new Uint8Array(16),ae=new Uint8Array(64),Ee,me;for(me=0;me<16;me++)J[me]=0;for(me=0;me<8;me++)J[me]=L[me];for(;_>=64;){for(H(ae,J,F,M),me=0;me<64;me++)m[E+me]=g[d+me]^ae[me];for(Ee=1,me=8;me<16;me++)Ee=Ee+(J[me]&255)|0,J[me]=Ee&255,Ee>>>=8;_-=64,E+=64,d+=64}if(_>0)for(H(ae,J,F,M),me=0;me<_;me++)m[E+me]=g[d+me]^ae[me];return 0}function N(m,E,g,d,_){var L=new Uint8Array(16),F=new Uint8Array(64),J,ae;for(ae=0;ae<16;ae++)L[ae]=0;for(ae=0;ae<8;ae++)L[ae]=d[ae];for(;g>=64;){for(H(F,L,_,M),ae=0;ae<64;ae++)m[E+ae]=F[ae];for(J=1,ae=8;ae<16;ae++)J=J+(L[ae]&255)|0,L[ae]=J&255,J>>>=8;g-=64,E+=64}if(g>0)for(H(F,L,_,M),ae=0;ae<g;ae++)m[E+ae]=F[ae];return 0}function S(m,E,g,d,_){var L=new Uint8Array(32);C(L,d,_,M);for(var F=new Uint8Array(8),J=0;J<8;J++)F[J]=d[J+16];return N(m,E,g,F,L)}function w(m,E,g,d,_,L,F){var J=new Uint8Array(32);C(J,L,F,M);for(var ae=new Uint8Array(8),Ee=0;Ee<8;Ee++)ae[Ee]=L[Ee+16];return Q(m,E,g,d,_,ae,J)}var v=function(m){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 E,g,d,_,L,F,J,ae;E=m[0]&255|(m[1]&255)<<8,this.r[0]=E&8191,g=m[2]&255|(m[3]&255)<<8,this.r[1]=(E>>>13|g<<3)&8191,d=m[4]&255|(m[5]&255)<<8,this.r[2]=(g>>>10|d<<6)&7939,_=m[6]&255|(m[7]&255)<<8,this.r[3]=(d>>>7|_<<9)&8191,L=m[8]&255|(m[9]&255)<<8,this.r[4]=(_>>>4|L<<12)&255,this.r[5]=L>>>1&8190,F=m[10]&255|(m[11]&255)<<8,this.r[6]=(L>>>14|F<<2)&8191,J=m[12]&255|(m[13]&255)<<8,this.r[7]=(F>>>11|J<<5)&8065,ae=m[14]&255|(m[15]&255)<<8,this.r[8]=(J>>>8|ae<<8)&8191,this.r[9]=ae>>>5&127,this.pad[0]=m[16]&255|(m[17]&255)<<8,this.pad[1]=m[18]&255|(m[19]&255)<<8,this.pad[2]=m[20]&255|(m[21]&255)<<8,this.pad[3]=m[22]&255|(m[23]&255)<<8,this.pad[4]=m[24]&255|(m[25]&255)<<8,this.pad[5]=m[26]&255|(m[27]&255)<<8,this.pad[6]=m[28]&255|(m[29]&255)<<8,this.pad[7]=m[30]&255|(m[31]&255)<<8};v.prototype.blocks=function(m,E,g){for(var d=this.fin?0:2048,_,L,F,J,ae,Ee,me,it,Ae,Oe,Le,Qe,Fe,De,Ue,Me,ye,be,ge,_e=this.h[0],Se=this.h[1],pe=this.h[2],W=this.h[3],q=this.h[4],re=this.h[5],X=this.h[6],Z=this.h[7],oe=this.h[8],ve=this.h[9],We=this.r[0],Ke=this.r[1],qe=this.r[2],I=this.r[3],ze=this.r[4],st=this.r[5],ot=this.r[6],Ve=this.r[7],et=this.r[8],tt=this.r[9];g>=16;)_=m[E+0]&255|(m[E+1]&255)<<8,_e+=_&8191,L=m[E+2]&255|(m[E+3]&255)<<8,Se+=(_>>>13|L<<3)&8191,F=m[E+4]&255|(m[E+5]&255)<<8,pe+=(L>>>10|F<<6)&8191,J=m[E+6]&255|(m[E+7]&255)<<8,W+=(F>>>7|J<<9)&8191,ae=m[E+8]&255|(m[E+9]&255)<<8,q+=(J>>>4|ae<<12)&8191,re+=ae>>>1&8191,Ee=m[E+10]&255|(m[E+11]&255)<<8,X+=(ae>>>14|Ee<<2)&8191,me=m[E+12]&255|(m[E+13]&255)<<8,Z+=(Ee>>>11|me<<5)&8191,it=m[E+14]&255|(m[E+15]&255)<<8,oe+=(me>>>8|it<<8)&8191,ve+=it>>>5|d,Ae=0,Oe=Ae,Oe+=_e*We,Oe+=Se*(5*tt),Oe+=pe*(5*et),Oe+=W*(5*Ve),Oe+=q*(5*ot),Ae=Oe>>>13,Oe&=8191,Oe+=re*(5*st),Oe+=X*(5*ze),Oe+=Z*(5*I),Oe+=oe*(5*qe),Oe+=ve*(5*Ke),Ae+=Oe>>>13,Oe&=8191,Le=Ae,Le+=_e*Ke,Le+=Se*We,Le+=pe*(5*tt),Le+=W*(5*et),Le+=q*(5*Ve),Ae=Le>>>13,Le&=8191,Le+=re*(5*ot),Le+=X*(5*st),Le+=Z*(5*ze),Le+=oe*(5*I),Le+=ve*(5*qe),Ae+=Le>>>13,Le&=8191,Qe=Ae,Qe+=_e*qe,Qe+=Se*Ke,Qe+=pe*We,Qe+=W*(5*tt),Qe+=q*(5*et),Ae=Qe>>>13,Qe&=8191,Qe+=re*(5*Ve),Qe+=X*(5*ot),Qe+=Z*(5*st),Qe+=oe*(5*ze),Qe+=ve*(5*I),Ae+=Qe>>>13,Qe&=8191,Fe=Ae,Fe+=_e*I,Fe+=Se*qe,Fe+=pe*Ke,Fe+=W*We,Fe+=q*(5*tt),Ae=Fe>>>13,Fe&=8191,Fe+=re*(5*et),Fe+=X*(5*Ve),Fe+=Z*(5*ot),Fe+=oe*(5*st),Fe+=ve*(5*ze),Ae+=Fe>>>13,Fe&=8191,De=Ae,De+=_e*ze,De+=Se*I,De+=pe*qe,De+=W*Ke,De+=q*We,Ae=De>>>13,De&=8191,De+=re*(5*tt),De+=X*(5*et),De+=Z*(5*Ve),De+=oe*(5*ot),De+=ve*(5*st),Ae+=De>>>13,De&=8191,Ue=Ae,Ue+=_e*st,Ue+=Se*ze,Ue+=pe*I,Ue+=W*qe,Ue+=q*Ke,Ae=Ue>>>13,Ue&=8191,Ue+=re*We,Ue+=X*(5*tt),Ue+=Z*(5*et),Ue+=oe*(5*Ve),Ue+=ve*(5*ot),Ae+=Ue>>>13,Ue&=8191,Me=Ae,Me+=_e*ot,Me+=Se*st,Me+=pe*ze,Me+=W*I,Me+=q*qe,Ae=Me>>>13,Me&=8191,Me+=re*Ke,Me+=X*We,Me+=Z*(5*tt),Me+=oe*(5*et),Me+=ve*(5*Ve),Ae+=Me>>>13,Me&=8191,ye=Ae,ye+=_e*Ve,ye+=Se*ot,ye+=pe*st,ye+=W*ze,ye+=q*I,Ae=ye>>>13,ye&=8191,ye+=re*qe,ye+=X*Ke,ye+=Z*We,ye+=oe*(5*tt),ye+=ve*(5*et),Ae+=ye>>>13,ye&=8191,be=Ae,be+=_e*et,be+=Se*Ve,be+=pe*ot,be+=W*st,be+=q*ze,Ae=be>>>13,be&=8191,be+=re*I,be+=X*qe,be+=Z*Ke,be+=oe*We,be+=ve*(5*tt),Ae+=be>>>13,be&=8191,ge=Ae,ge+=_e*tt,ge+=Se*et,ge+=pe*Ve,ge+=W*ot,ge+=q*st,Ae=ge>>>13,ge&=8191,ge+=re*ze,ge+=X*I,ge+=Z*qe,ge+=oe*Ke,ge+=ve*We,Ae+=ge>>>13,ge&=8191,Ae=(Ae<<2)+Ae|0,Ae=Ae+Oe|0,Oe=Ae&8191,Ae=Ae>>>13,Le+=Ae,_e=Oe,Se=Le,pe=Qe,W=Fe,q=De,re=Ue,X=Me,Z=ye,oe=be,ve=ge,E+=16,g-=16;this.h[0]=_e,this.h[1]=Se,this.h[2]=pe,this.h[3]=W,this.h[4]=q,this.h[5]=re,this.h[6]=X,this.h[7]=Z,this.h[8]=oe,this.h[9]=ve},v.prototype.finish=function(m,E){var g=new Uint16Array(10),d,_,L,F;if(this.leftover){for(F=this.leftover,this.buffer[F++]=1;F<16;F++)this.buffer[F]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(d=this.h[1]>>>13,this.h[1]&=8191,F=2;F<10;F++)this.h[F]+=d,d=this.h[F]>>>13,this.h[F]&=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,g[0]=this.h[0]+5,d=g[0]>>>13,g[0]&=8191,F=1;F<10;F++)g[F]=this.h[F]+d,d=g[F]>>>13,g[F]&=8191;for(g[9]-=8192,_=(d^1)-1,F=0;F<10;F++)g[F]&=_;for(_=~_,F=0;F<10;F++)this.h[F]=this.h[F]&_|g[F];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,L=this.h[0]+this.pad[0],this.h[0]=L&65535,F=1;F<8;F++)L=(this.h[F]+this.pad[F]|0)+(L>>>16)|0,this.h[F]=L&65535;m[E+0]=this.h[0]>>>0&255,m[E+1]=this.h[0]>>>8&255,m[E+2]=this.h[1]>>>0&255,m[E+3]=this.h[1]>>>8&255,m[E+4]=this.h[2]>>>0&255,m[E+5]=this.h[2]>>>8&255,m[E+6]=this.h[3]>>>0&255,m[E+7]=this.h[3]>>>8&255,m[E+8]=this.h[4]>>>0&255,m[E+9]=this.h[4]>>>8&255,m[E+10]=this.h[5]>>>0&255,m[E+11]=this.h[5]>>>8&255,m[E+12]=this.h[6]>>>0&255,m[E+13]=this.h[6]>>>8&255,m[E+14]=this.h[7]>>>0&255,m[E+15]=this.h[7]>>>8&255},v.prototype.update=function(m,E,g){var d,_;if(this.leftover){for(_=16-this.leftover,_>g&&(_=g),d=0;d<_;d++)this.buffer[this.leftover+d]=m[E+d];if(g-=_,E+=_,this.leftover+=_,this.leftover<16)return;this.blocks(this.buffer,0,16),this.leftover=0}if(g>=16&&(_=g-g%16,this.blocks(m,E,_),E+=_,g-=_),g){for(d=0;d<g;d++)this.buffer[this.leftover+d]=m[E+d];this.leftover+=g}};function k(m,E,g,d,_,L){var F=new v(L);return F.update(g,d,_),F.finish(m,E),0}function P(m,E,g,d,_,L){var F=new Uint8Array(16);return k(F,0,g,d,_,L),y(m,E,F,0)}function ne(m,E,g,d,_){var L;if(g<32)return-1;for(w(m,0,E,0,g,d,_),k(m,16,m,32,g-32,m),L=0;L<16;L++)m[L]=0;return 0}function Y(m,E,g,d,_){var L,F=new Uint8Array(32);if(g<32||(S(F,0,32,d,_),P(E,16,E,32,g-32,F)!==0))return-1;for(w(m,0,E,0,g,d,_),L=0;L<32;L++)m[L]=0;return 0}function G(m,E){var g;for(g=0;g<16;g++)m[g]=E[g]|0}function te(m){var E,g,d=1;for(E=0;E<16;E++)g=m[E]+d+65535,d=Math.floor(g/65536),m[E]=g-d*65536;m[0]+=d-1+37*(d-1)}function le(m,E,g){for(var d,_=~(g-1),L=0;L<16;L++)d=_&(m[L]^E[L]),m[L]^=d,E[L]^=d}function U(m,E){var g,d,_,L=t(),F=t();for(g=0;g<16;g++)F[g]=E[g];for(te(F),te(F),te(F),d=0;d<2;d++){for(L[0]=F[0]-65517,g=1;g<15;g++)L[g]=F[g]-65535-(L[g-1]>>16&1),L[g-1]&=65535;L[15]=F[15]-32767-(L[14]>>16&1),_=L[15]>>16&1,L[14]&=65535,le(F,L,1-_)}for(g=0;g<16;g++)m[2*g]=F[g]&255,m[2*g+1]=F[g]>>8}function R(m,E){var g=new Uint8Array(32),d=new Uint8Array(32);return U(g,m),U(d,E),b(g,0,d,0)}function O(m){var E=new Uint8Array(32);return U(E,m),E[0]&1}function K(m,E){var g;for(g=0;g<16;g++)m[g]=E[2*g]+(E[2*g+1]<<8);m[15]&=32767}function ee(m,E,g){for(var d=0;d<16;d++)m[d]=E[d]+g[d]}function ue(m,E,g){for(var d=0;d<16;d++)m[d]=E[d]-g[d]}function ie(m,E,g){var d,_,L=0,F=0,J=0,ae=0,Ee=0,me=0,it=0,Ae=0,Oe=0,Le=0,Qe=0,Fe=0,De=0,Ue=0,Me=0,ye=0,be=0,ge=0,_e=0,Se=0,pe=0,W=0,q=0,re=0,X=0,Z=0,oe=0,ve=0,We=0,Ke=0,qe=0,I=g[0],ze=g[1],st=g[2],ot=g[3],Ve=g[4],et=g[5],tt=g[6],Rt=g[7],ht=g[8],kt=g[9],Nt=g[10],Bt=g[11],Ut=g[12],zt=g[13],Yt=g[14],Gt=g[15];d=E[0],L+=d*I,F+=d*ze,J+=d*st,ae+=d*ot,Ee+=d*Ve,me+=d*et,it+=d*tt,Ae+=d*Rt,Oe+=d*ht,Le+=d*kt,Qe+=d*Nt,Fe+=d*Bt,De+=d*Ut,Ue+=d*zt,Me+=d*Yt,ye+=d*Gt,d=E[1],F+=d*I,J+=d*ze,ae+=d*st,Ee+=d*ot,me+=d*Ve,it+=d*et,Ae+=d*tt,Oe+=d*Rt,Le+=d*ht,Qe+=d*kt,Fe+=d*Nt,De+=d*Bt,Ue+=d*Ut,Me+=d*zt,ye+=d*Yt,be+=d*Gt,d=E[2],J+=d*I,ae+=d*ze,Ee+=d*st,me+=d*ot,it+=d*Ve,Ae+=d*et,Oe+=d*tt,Le+=d*Rt,Qe+=d*ht,Fe+=d*kt,De+=d*Nt,Ue+=d*Bt,Me+=d*Ut,ye+=d*zt,be+=d*Yt,ge+=d*Gt,d=E[3],ae+=d*I,Ee+=d*ze,me+=d*st,it+=d*ot,Ae+=d*Ve,Oe+=d*et,Le+=d*tt,Qe+=d*Rt,Fe+=d*ht,De+=d*kt,Ue+=d*Nt,Me+=d*Bt,ye+=d*Ut,be+=d*zt,ge+=d*Yt,_e+=d*Gt,d=E[4],Ee+=d*I,me+=d*ze,it+=d*st,Ae+=d*ot,Oe+=d*Ve,Le+=d*et,Qe+=d*tt,Fe+=d*Rt,De+=d*ht,Ue+=d*kt,Me+=d*Nt,ye+=d*Bt,be+=d*Ut,ge+=d*zt,_e+=d*Yt,Se+=d*Gt,d=E[5],me+=d*I,it+=d*ze,Ae+=d*st,Oe+=d*ot,Le+=d*Ve,Qe+=d*et,Fe+=d*tt,De+=d*Rt,Ue+=d*ht,Me+=d*kt,ye+=d*Nt,be+=d*Bt,ge+=d*Ut,_e+=d*zt,Se+=d*Yt,pe+=d*Gt,d=E[6],it+=d*I,Ae+=d*ze,Oe+=d*st,Le+=d*ot,Qe+=d*Ve,Fe+=d*et,De+=d*tt,Ue+=d*Rt,Me+=d*ht,ye+=d*kt,be+=d*Nt,ge+=d*Bt,_e+=d*Ut,Se+=d*zt,pe+=d*Yt,W+=d*Gt,d=E[7],Ae+=d*I,Oe+=d*ze,Le+=d*st,Qe+=d*ot,Fe+=d*Ve,De+=d*et,Ue+=d*tt,Me+=d*Rt,ye+=d*ht,be+=d*kt,ge+=d*Nt,_e+=d*Bt,Se+=d*Ut,pe+=d*zt,W+=d*Yt,q+=d*Gt,d=E[8],Oe+=d*I,Le+=d*ze,Qe+=d*st,Fe+=d*ot,De+=d*Ve,Ue+=d*et,Me+=d*tt,ye+=d*Rt,be+=d*ht,ge+=d*kt,_e+=d*Nt,Se+=d*Bt,pe+=d*Ut,W+=d*zt,q+=d*Yt,re+=d*Gt,d=E[9],Le+=d*I,Qe+=d*ze,Fe+=d*st,De+=d*ot,Ue+=d*Ve,Me+=d*et,ye+=d*tt,be+=d*Rt,ge+=d*ht,_e+=d*kt,Se+=d*Nt,pe+=d*Bt,W+=d*Ut,q+=d*zt,re+=d*Yt,X+=d*Gt,d=E[10],Qe+=d*I,Fe+=d*ze,De+=d*st,Ue+=d*ot,Me+=d*Ve,ye+=d*et,be+=d*tt,ge+=d*Rt,_e+=d*ht,Se+=d*kt,pe+=d*Nt,W+=d*Bt,q+=d*Ut,re+=d*zt,X+=d*Yt,Z+=d*Gt,d=E[11],Fe+=d*I,De+=d*ze,Ue+=d*st,Me+=d*ot,ye+=d*Ve,be+=d*et,ge+=d*tt,_e+=d*Rt,Se+=d*ht,pe+=d*kt,W+=d*Nt,q+=d*Bt,re+=d*Ut,X+=d*zt,Z+=d*Yt,oe+=d*Gt,d=E[12],De+=d*I,Ue+=d*ze,Me+=d*st,ye+=d*ot,be+=d*Ve,ge+=d*et,_e+=d*tt,Se+=d*Rt,pe+=d*ht,W+=d*kt,q+=d*Nt,re+=d*Bt,X+=d*Ut,Z+=d*zt,oe+=d*Yt,ve+=d*Gt,d=E[13],Ue+=d*I,Me+=d*ze,ye+=d*st,be+=d*ot,ge+=d*Ve,_e+=d*et,Se+=d*tt,pe+=d*Rt,W+=d*ht,q+=d*kt,re+=d*Nt,X+=d*Bt,Z+=d*Ut,oe+=d*zt,ve+=d*Yt,We+=d*Gt,d=E[14],Me+=d*I,ye+=d*ze,be+=d*st,ge+=d*ot,_e+=d*Ve,Se+=d*et,pe+=d*tt,W+=d*Rt,q+=d*ht,re+=d*kt,X+=d*Nt,Z+=d*Bt,oe+=d*Ut,ve+=d*zt,We+=d*Yt,Ke+=d*Gt,d=E[15],ye+=d*I,be+=d*ze,ge+=d*st,_e+=d*ot,Se+=d*Ve,pe+=d*et,W+=d*tt,q+=d*Rt,re+=d*ht,X+=d*kt,Z+=d*Nt,oe+=d*Bt,ve+=d*Ut,We+=d*zt,Ke+=d*Yt,qe+=d*Gt,L+=38*be,F+=38*ge,J+=38*_e,ae+=38*Se,Ee+=38*pe,me+=38*W,it+=38*q,Ae+=38*re,Oe+=38*X,Le+=38*Z,Qe+=38*oe,Fe+=38*ve,De+=38*We,Ue+=38*Ke,Me+=38*qe,_=1,d=L+_+65535,_=Math.floor(d/65536),L=d-_*65536,d=F+_+65535,_=Math.floor(d/65536),F=d-_*65536,d=J+_+65535,_=Math.floor(d/65536),J=d-_*65536,d=ae+_+65535,_=Math.floor(d/65536),ae=d-_*65536,d=Ee+_+65535,_=Math.floor(d/65536),Ee=d-_*65536,d=me+_+65535,_=Math.floor(d/65536),me=d-_*65536,d=it+_+65535,_=Math.floor(d/65536),it=d-_*65536,d=Ae+_+65535,_=Math.floor(d/65536),Ae=d-_*65536,d=Oe+_+65535,_=Math.floor(d/65536),Oe=d-_*65536,d=Le+_+65535,_=Math.floor(d/65536),Le=d-_*65536,d=Qe+_+65535,_=Math.floor(d/65536),Qe=d-_*65536,d=Fe+_+65535,_=Math.floor(d/65536),Fe=d-_*65536,d=De+_+65535,_=Math.floor(d/65536),De=d-_*65536,d=Ue+_+65535,_=Math.floor(d/65536),Ue=d-_*65536,d=Me+_+65535,_=Math.floor(d/65536),Me=d-_*65536,d=ye+_+65535,_=Math.floor(d/65536),ye=d-_*65536,L+=_-1+37*(_-1),_=1,d=L+_+65535,_=Math.floor(d/65536),L=d-_*65536,d=F+_+65535,_=Math.floor(d/65536),F=d-_*65536,d=J+_+65535,_=Math.floor(d/65536),J=d-_*65536,d=ae+_+65535,_=Math.floor(d/65536),ae=d-_*65536,d=Ee+_+65535,_=Math.floor(d/65536),Ee=d-_*65536,d=me+_+65535,_=Math.floor(d/65536),me=d-_*65536,d=it+_+65535,_=Math.floor(d/65536),it=d-_*65536,d=Ae+_+65535,_=Math.floor(d/65536),Ae=d-_*65536,d=Oe+_+65535,_=Math.floor(d/65536),Oe=d-_*65536,d=Le+_+65535,_=Math.floor(d/65536),Le=d-_*65536,d=Qe+_+65535,_=Math.floor(d/65536),Qe=d-_*65536,d=Fe+_+65535,_=Math.floor(d/65536),Fe=d-_*65536,d=De+_+65535,_=Math.floor(d/65536),De=d-_*65536,d=Ue+_+65535,_=Math.floor(d/65536),Ue=d-_*65536,d=Me+_+65535,_=Math.floor(d/65536),Me=d-_*65536,d=ye+_+65535,_=Math.floor(d/65536),ye=d-_*65536,L+=_-1+37*(_-1),m[0]=L,m[1]=F,m[2]=J,m[3]=ae,m[4]=Ee,m[5]=me,m[6]=it,m[7]=Ae,m[8]=Oe,m[9]=Le,m[10]=Qe,m[11]=Fe,m[12]=De,m[13]=Ue,m[14]=Me,m[15]=ye}function Xe(m,E){ie(m,E,E)}function dt(m,E){var g=t(),d;for(d=0;d<16;d++)g[d]=E[d];for(d=253;d>=0;d--)Xe(g,g),d!==2&&d!==4&&ie(g,g,E);for(d=0;d<16;d++)m[d]=g[d]}function cn(m,E){var g=t(),d;for(d=0;d<16;d++)g[d]=E[d];for(d=250;d>=0;d--)Xe(g,g),d!==1&&ie(g,g,E);for(d=0;d<16;d++)m[d]=g[d]}function br(m,E,g){var d=new Uint8Array(32),_=new Float64Array(80),L,F,J=t(),ae=t(),Ee=t(),me=t(),it=t(),Ae=t();for(F=0;F<31;F++)d[F]=E[F];for(d[31]=E[31]&127|64,d[0]&=248,K(_,g),F=0;F<16;F++)ae[F]=_[F],me[F]=J[F]=Ee[F]=0;for(J[0]=me[0]=1,F=254;F>=0;--F)L=d[F>>>3]>>>(F&7)&1,le(J,ae,L),le(Ee,me,L),ee(it,J,Ee),ue(J,J,Ee),ee(Ee,ae,me),ue(ae,ae,me),Xe(me,it),Xe(Ae,J),ie(J,Ee,J),ie(Ee,ae,it),ee(it,J,Ee),ue(J,J,Ee),Xe(ae,J),ue(Ee,me,Ae),ie(J,Ee,a),ee(J,J,me),ie(Ee,Ee,J),ie(J,me,Ae),ie(me,ae,_),Xe(ae,it),le(J,ae,L),le(Ee,me,L);for(F=0;F<16;F++)_[F+16]=J[F],_[F+32]=Ee[F],_[F+48]=ae[F],_[F+64]=me[F];var Oe=_.subarray(32),Le=_.subarray(16);return dt(Oe,Oe),ie(Le,Le,Oe),U(m,Le),0}function xr(m,E){return br(m,E,s)}function Ln(m,E){return e(E,32),xr(m,E)}function wr(m,E,g){var d=new Uint8Array(32);return br(d,g,E),C(m,r,d,M)}var ci=ne,ss=Y;function li(m,E,g,d,_,L){var F=new Uint8Array(32);return wr(F,_,L),ci(m,E,g,d,F)}function Ir(m,E,g,d,_,L){var F=new Uint8Array(32);return wr(F,_,L),ss(m,E,g,d,F)}var Cr=[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 j(m,E,g,d){for(var _=new Int32Array(16),L=new Int32Array(16),F,J,ae,Ee,me,it,Ae,Oe,Le,Qe,Fe,De,Ue,Me,ye,be,ge,_e,Se,pe,W,q,re,X,Z,oe,ve=m[0],We=m[1],Ke=m[2],qe=m[3],I=m[4],ze=m[5],st=m[6],ot=m[7],Ve=E[0],et=E[1],tt=E[2],Rt=E[3],ht=E[4],kt=E[5],Nt=E[6],Bt=E[7],Ut=0;d>=128;){for(Se=0;Se<16;Se++)pe=8*Se+Ut,_[Se]=g[pe+0]<<24|g[pe+1]<<16|g[pe+2]<<8|g[pe+3],L[Se]=g[pe+4]<<24|g[pe+5]<<16|g[pe+6]<<8|g[pe+7];for(Se=0;Se<80;Se++)if(F=ve,J=We,ae=Ke,Ee=qe,me=I,it=ze,Ae=st,Oe=ot,Le=Ve,Qe=et,Fe=tt,De=Rt,Ue=ht,Me=kt,ye=Nt,be=Bt,W=ot,q=Bt,re=q&65535,X=q>>>16,Z=W&65535,oe=W>>>16,W=(I>>>14|ht<<18)^(I>>>18|ht<<14)^(ht>>>9|I<<23),q=(ht>>>14|I<<18)^(ht>>>18|I<<14)^(I>>>9|ht<<23),re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,W=I&ze^~I&st,q=ht&kt^~ht&Nt,re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,W=Cr[Se*2],q=Cr[Se*2+1],re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,W=_[Se%16],q=L[Se%16],re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,ge=Z&65535|oe<<16,_e=re&65535|X<<16,W=ge,q=_e,re=q&65535,X=q>>>16,Z=W&65535,oe=W>>>16,W=(ve>>>28|Ve<<4)^(Ve>>>2|ve<<30)^(Ve>>>7|ve<<25),q=(Ve>>>28|ve<<4)^(ve>>>2|Ve<<30)^(ve>>>7|Ve<<25),re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,W=ve&We^ve&Ke^We&Ke,q=Ve&et^Ve&tt^et&tt,re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,Oe=Z&65535|oe<<16,be=re&65535|X<<16,W=Ee,q=De,re=q&65535,X=q>>>16,Z=W&65535,oe=W>>>16,W=ge,q=_e,re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,Ee=Z&65535|oe<<16,De=re&65535|X<<16,We=F,Ke=J,qe=ae,I=Ee,ze=me,st=it,ot=Ae,ve=Oe,et=Le,tt=Qe,Rt=Fe,ht=De,kt=Ue,Nt=Me,Bt=ye,Ve=be,Se%16===15)for(pe=0;pe<16;pe++)W=_[pe],q=L[pe],re=q&65535,X=q>>>16,Z=W&65535,oe=W>>>16,W=_[(pe+9)%16],q=L[(pe+9)%16],re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,ge=_[(pe+1)%16],_e=L[(pe+1)%16],W=(ge>>>1|_e<<31)^(ge>>>8|_e<<24)^ge>>>7,q=(_e>>>1|ge<<31)^(_e>>>8|ge<<24)^(_e>>>7|ge<<25),re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,ge=_[(pe+14)%16],_e=L[(pe+14)%16],W=(ge>>>19|_e<<13)^(_e>>>29|ge<<3)^ge>>>6,q=(_e>>>19|ge<<13)^(ge>>>29|_e<<3)^(_e>>>6|ge<<26),re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,_[pe]=Z&65535|oe<<16,L[pe]=re&65535|X<<16;W=ve,q=Ve,re=q&65535,X=q>>>16,Z=W&65535,oe=W>>>16,W=m[0],q=E[0],re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,m[0]=ve=Z&65535|oe<<16,E[0]=Ve=re&65535|X<<16,W=We,q=et,re=q&65535,X=q>>>16,Z=W&65535,oe=W>>>16,W=m[1],q=E[1],re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,m[1]=We=Z&65535|oe<<16,E[1]=et=re&65535|X<<16,W=Ke,q=tt,re=q&65535,X=q>>>16,Z=W&65535,oe=W>>>16,W=m[2],q=E[2],re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,m[2]=Ke=Z&65535|oe<<16,E[2]=tt=re&65535|X<<16,W=qe,q=Rt,re=q&65535,X=q>>>16,Z=W&65535,oe=W>>>16,W=m[3],q=E[3],re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,m[3]=qe=Z&65535|oe<<16,E[3]=Rt=re&65535|X<<16,W=I,q=ht,re=q&65535,X=q>>>16,Z=W&65535,oe=W>>>16,W=m[4],q=E[4],re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,m[4]=I=Z&65535|oe<<16,E[4]=ht=re&65535|X<<16,W=ze,q=kt,re=q&65535,X=q>>>16,Z=W&65535,oe=W>>>16,W=m[5],q=E[5],re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,m[5]=ze=Z&65535|oe<<16,E[5]=kt=re&65535|X<<16,W=st,q=Nt,re=q&65535,X=q>>>16,Z=W&65535,oe=W>>>16,W=m[6],q=E[6],re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,m[6]=st=Z&65535|oe<<16,E[6]=Nt=re&65535|X<<16,W=ot,q=Bt,re=q&65535,X=q>>>16,Z=W&65535,oe=W>>>16,W=m[7],q=E[7],re+=q&65535,X+=q>>>16,Z+=W&65535,oe+=W>>>16,X+=re>>>16,Z+=X>>>16,oe+=Z>>>16,m[7]=ot=Z&65535|oe<<16,E[7]=Bt=re&65535|X<<16,Ut+=128,d-=128}return d}function he(m,E,g){var d=new Int32Array(8),_=new Int32Array(8),L=new Uint8Array(256),F,J=g;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,_[0]=4089235720,_[1]=2227873595,_[2]=4271175723,_[3]=1595750129,_[4]=2917565137,_[5]=725511199,_[6]=4215389547,_[7]=327033209,j(d,_,E,g),g%=128,F=0;F<g;F++)L[F]=E[J-g+F];for(L[g]=128,g=256-128*(g<112?1:0),L[g-9]=0,p(L,g-8,J/536870912|0,J<<3),j(d,_,L,g),F=0;F<8;F++)p(m,8*F,d[F],_[F]);return 0}function xe(m,E){var g=t(),d=t(),_=t(),L=t(),F=t(),J=t(),ae=t(),Ee=t(),me=t();ue(g,m[1],m[0]),ue(me,E[1],E[0]),ie(g,g,me),ee(d,m[0],m[1]),ee(me,E[0],E[1]),ie(d,d,me),ie(_,m[3],E[3]),ie(_,_,l),ie(L,m[2],E[2]),ee(L,L,L),ue(F,d,g),ue(J,L,_),ee(ae,L,_),ee(Ee,d,g),ie(m[0],F,J),ie(m[1],Ee,ae),ie(m[2],ae,J),ie(m[3],F,Ee)}function Te(m,E,g){var d;for(d=0;d<4;d++)le(m[d],E[d],g)}function Je(m,E){var g=t(),d=t(),_=t();dt(_,E[2]),ie(g,E[0],_),ie(d,E[1],_),U(m,d),m[31]^=O(g)<<7}function Lt(m,E,g){var d,_;for(G(m[0],i),G(m[1],o),G(m[2],o),G(m[3],i),_=255;_>=0;--_)d=g[_/8|0]>>(_&7)&1,Te(m,E,d),xe(E,m),xe(m,m),Te(m,E,d)}function vn(m,E){var g=[t(),t(),t(),t()];G(g[0],f),G(g[1],u),G(g[2],o),ie(g[3],f,u),Lt(m,g,E)}function ln(m,E,g){var d=new Uint8Array(64),_=[t(),t(),t(),t()],L;for(g||e(E,32),he(d,E,32),d[0]&=248,d[31]&=127,d[31]|=64,vn(_,d),Je(m,_),L=0;L<32;L++)E[L+32]=m[L];return 0}var vr=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 ct(m,E){var g,d,_,L;for(d=63;d>=32;--d){for(g=0,_=d-32,L=d-12;_<L;++_)E[_]+=g-16*E[d]*vr[_-(d-32)],g=E[_]+128>>8,E[_]-=g*256;E[_]+=g,E[d]=0}for(g=0,_=0;_<32;_++)E[_]+=g-(E[31]>>4)*vr[_],g=E[_]>>8,E[_]&=255;for(_=0;_<32;_++)E[_]-=g*vr[_];for(d=0;d<32;d++)E[d+1]+=E[d]>>8,m[d]=E[d]&255}function $t(m){var E=new Float64Array(64),g;for(g=0;g<64;g++)E[g]=m[g];for(g=0;g<64;g++)m[g]=0;ct(m,E)}function Mt(m,E,g,d){var _=new Uint8Array(64),L=new Uint8Array(64),F=new Uint8Array(64),J,ae,Ee=new Float64Array(64),me=[t(),t(),t(),t()];he(_,d,32),_[0]&=248,_[31]&=127,_[31]|=64;var it=g+64;for(J=0;J<g;J++)m[64+J]=E[J];for(J=0;J<32;J++)m[32+J]=_[32+J];for(he(F,m.subarray(32),g+32),$t(F),vn(me,F),Je(m,me),J=32;J<64;J++)m[J]=d[J];for(he(L,m,g+64),$t(L),J=0;J<64;J++)Ee[J]=0;for(J=0;J<32;J++)Ee[J]=F[J];for(J=0;J<32;J++)for(ae=0;ae<32;ae++)Ee[J+ae]+=L[J]*_[ae];return ct(m.subarray(32),Ee),it}function Ct(m,E){var g=t(),d=t(),_=t(),L=t(),F=t(),J=t(),ae=t();return G(m[2],o),K(m[1],E),Xe(_,m[1]),ie(L,_,c),ue(_,_,m[2]),ee(L,m[2],L),Xe(F,L),Xe(J,F),ie(ae,J,F),ie(g,ae,_),ie(g,g,L),cn(g,g),ie(g,g,_),ie(g,g,L),ie(g,g,L),ie(m[0],g,L),Xe(d,m[0]),ie(d,d,L),R(d,_)&&ie(m[0],m[0],h),Xe(d,m[0]),ie(d,d,L),R(d,_)?-1:(O(m[0])===E[31]>>7&&ue(m[0],i,m[0]),ie(m[3],m[0],m[1]),0)}function gt(m,E,g,d){var _,L,F=new Uint8Array(32),J=new Uint8Array(64),ae=[t(),t(),t(),t()],Ee=[t(),t(),t(),t()];if(L=-1,g<64||Ct(Ee,d))return-1;for(_=0;_<g;_++)m[_]=E[_];for(_=0;_<32;_++)m[_+32]=d[_];if(he(J,m,g),$t(J),Lt(ae,Ee,J),vn(Ee,E.subarray(32)),xe(ae,Ee),Je(F,ae),g-=64,b(E,0,F,0)){for(_=0;_<g;_++)m[_]=0;return-1}for(_=0;_<g;_++)m[_]=E[_+64];return L=g,L}var pn=32,vt=24,lr=32,kr=16,fi=32,os=32,ui=32,di=32,So=32,Wc=vt,_p=lr,Sp=kr,Dn=64,fr=32,Nr=64,bo=32,xo=64;n.lowlevel={crypto_core_hsalsa20:C,crypto_stream_xor:w,crypto_stream:S,crypto_stream_salsa20_xor:Q,crypto_stream_salsa20:N,crypto_onetimeauth:k,crypto_onetimeauth_verify:P,crypto_verify_16:y,crypto_verify_32:b,crypto_secretbox:ne,crypto_secretbox_open:Y,crypto_scalarmult:br,crypto_scalarmult_base:xr,crypto_box_beforenm:wr,crypto_box_afternm:ci,crypto_box:li,crypto_box_open:Ir,crypto_box_keypair:Ln,crypto_hash:he,crypto_sign:Mt,crypto_sign_keypair:ln,crypto_sign_open:gt,crypto_secretbox_KEYBYTES:pn,crypto_secretbox_NONCEBYTES:vt,crypto_secretbox_ZEROBYTES:lr,crypto_secretbox_BOXZEROBYTES:kr,crypto_scalarmult_BYTES:fi,crypto_scalarmult_SCALARBYTES:os,crypto_box_PUBLICKEYBYTES:ui,crypto_box_SECRETKEYBYTES:di,crypto_box_BEFORENMBYTES:So,crypto_box_NONCEBYTES:Wc,crypto_box_ZEROBYTES:_p,crypto_box_BOXZEROBYTES:Sp,crypto_sign_BYTES:Dn,crypto_sign_PUBLICKEYBYTES:fr,crypto_sign_SECRETKEYBYTES:Nr,crypto_sign_SEEDBYTES:bo,crypto_hash_BYTES:xo};function qc(m,E){if(m.length!==pn)throw new Error("bad key size");if(E.length!==vt)throw new Error("bad nonce size")}function bp(m,E){if(m.length!==ui)throw new Error("bad public key size");if(E.length!==di)throw new Error("bad secret key size")}function fn(){var m,E;for(E=0;E<arguments.length;E++)if((m=Object.prototype.toString.call(arguments[E]))!=="[object Uint8Array]")throw new TypeError("unexpected type "+m+", use Uint8Array")}function Kc(m){for(var E=0;E<m.length;E++)m[E]=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(m){var E=new Uint8Array(m);return e(E,m),E},n.secretbox=function(m,E,g){fn(m,E,g),qc(g,E);for(var d=new Uint8Array(lr+m.length),_=new Uint8Array(d.length),L=0;L<m.length;L++)d[L+lr]=m[L];return ne(_,d,d.length,E,g),_.subarray(kr)},n.secretbox.open=function(m,E,g){fn(m,E,g),qc(g,E);for(var d=new Uint8Array(kr+m.length),_=new Uint8Array(d.length),L=0;L<m.length;L++)d[L+kr]=m[L];return d.length<32||Y(_,d,d.length,E,g)!==0?!1:_.subarray(lr)},n.secretbox.keyLength=pn,n.secretbox.nonceLength=vt,n.secretbox.overheadLength=kr,n.scalarMult=function(m,E){if(fn(m,E),m.length!==os)throw new Error("bad n size");if(E.length!==fi)throw new Error("bad p size");var g=new Uint8Array(fi);return br(g,m,E),g},n.scalarMult.base=function(m){if(fn(m),m.length!==os)throw new Error("bad n size");var E=new Uint8Array(fi);return xr(E,m),E},n.scalarMult.scalarLength=os,n.scalarMult.groupElementLength=fi,n.box=function(m,E,g,d){var _=n.box.before(g,d);return n.secretbox(m,E,_)},n.box.before=function(m,E){fn(m,E),bp(m,E);var g=new Uint8Array(So);return wr(g,m,E),g},n.box.after=n.secretbox,n.box.open=function(m,E,g,d){var _=n.box.before(g,d);return n.secretbox.open(m,E,_)},n.box.open.after=n.secretbox.open,n.box.keyPair=function(){var m=new Uint8Array(ui),E=new Uint8Array(di);return Ln(m,E),{publicKey:m,secretKey:E}},n.box.keyPair.fromSecretKey=function(m){if(fn(m),m.length!==di)throw new Error("bad secret key size");var E=new Uint8Array(ui);return xr(E,m),{publicKey:E,secretKey:new Uint8Array(m)}},n.box.publicKeyLength=ui,n.box.secretKeyLength=di,n.box.sharedKeyLength=So,n.box.nonceLength=Wc,n.box.overheadLength=n.secretbox.overheadLength,n.sign=function(m,E){if(fn(m,E),E.length!==Nr)throw new Error("bad secret key size");var g=new Uint8Array(Dn+m.length);return Mt(g,m,m.length,E),g},n.sign.open=function(m,E){if(arguments.length!==2)throw new Error("nacl.sign.open accepts 2 arguments; did you mean to use nacl.sign.detached.verify?");if(fn(m,E),E.length!==fr)throw new Error("bad public key size");var g=new Uint8Array(m.length),d=gt(g,m,m.length,E);if(d<0)return null;for(var _=new Uint8Array(d),L=0;L<_.length;L++)_[L]=g[L];return _},n.sign.detached=function(m,E){for(var g=n.sign(m,E),d=new Uint8Array(Dn),_=0;_<d.length;_++)d[_]=g[_];return d},n.sign.detached.verify=function(m,E,g){if(fn(m,E,g),E.length!==Dn)throw new Error("bad signature size");if(g.length!==fr)throw new Error("bad public key size");var d=new Uint8Array(Dn+m.length),_=new Uint8Array(Dn+m.length),L;for(L=0;L<Dn;L++)d[L]=E[L];for(L=0;L<m.length;L++)d[L+Dn]=m[L];return gt(_,d,d.length,g)>=0},n.sign.keyPair=function(){var m=new Uint8Array(fr),E=new Uint8Array(Nr);return ln(m,E),{publicKey:m,secretKey:E}},n.sign.keyPair.fromSecretKey=function(m){if(fn(m),m.length!==Nr)throw new Error("bad secret key size");for(var E=new Uint8Array(fr),g=0;g<E.length;g++)E[g]=m[32+g];return{publicKey:E,secretKey:new Uint8Array(m)}},n.sign.keyPair.fromSeed=function(m){if(fn(m),m.length!==bo)throw new Error("bad seed size");for(var E=new Uint8Array(fr),g=new Uint8Array(Nr),d=0;d<32;d++)g[d]=m[d];return ln(E,g,!0),{publicKey:E,secretKey:g}},n.sign.publicKeyLength=fr,n.sign.secretKeyLength=Nr,n.sign.seedLength=bo,n.sign.signatureLength=Dn,n.hash=function(m){fn(m);var E=new Uint8Array(xo);return he(E,m,m.length),E},n.hash.hashLength=xo,n.verify=function(m,E){return fn(m,E),m.length===0||E.length===0||m.length!==E.length?!1:A(m,0,E,0,m.length)===0},n.setPRNG=function(m){e=m},(function(){var m=typeof self<"u"?self.crypto||self.msCrypto:null;if(m&&m.getRandomValues){var E=65536;n.setPRNG(function(g,d){var _,L=new Uint8Array(d);for(_=0;_<d;_+=E)m.getRandomValues(L.subarray(_,_+Math.min(d-_,E)));for(_=0;_<d;_++)g[_]=L[_];Kc(L)})}else typeof require<"u"&&(m=require("crypto"),m&&m.randomBytes&&n.setPRNG(function(g,d){var _,L=m.randomBytes(d);for(_=0;_<d;_++)g[_]=L[_];Kc(L)}))})()})(typeof Ns<"u"&&Ns.exports?Ns.exports:self.nacl=self.nacl||{})});var Ko=lt((bx,Eu)=>{"use strict";var Qo=Au().lowlevel.crypto_hash,Fn=0,hr=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 Rs(n,t,e){return(n[0][t[e+3]]+n[1][t[e+2]]^n[2][t[e+1]])+n[3][t[e]]}hr.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]^=Rs(this.S,t,0)^this.P[e],n[0]^=Rs(this.S,t,4)^this.P[e+1];var r=n[0];n[0]=n[1]^this.P[17],n[1]=r};hr.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]^=Rs(this.S,t,0)^this.P[e],n[0]^=Rs(this.S,t,4)^this.P[e-1];var r=n[0];n[0]=n[1]^this.P[0],n[1]=r};function dr(n,t){var e,r=0;for(e=0;e<4;e++,Fn++)Fn>=t&&(Fn=0),r=r<<8|n[Fn];return r}hr.prototype.expand0state=function(n,t){var e=new Uint32Array(2),r,s,i=new Uint8Array(e.buffer);for(r=0,Fn=0;r<18;r++)this.P[r]^=dr(n,t);for(Fn=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]};hr.prototype.expandstate=function(n,t,e,r){var s=new Uint32Array(2),i,o;for(i=0,Fn=0;i<18;i++)this.P[i]^=dr(e,r);for(i=0,Fn=0;i<18;i+=2)s[0]^=dr(n,t),s[1]^=dr(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]^=dr(n,t),s[1]^=dr(n,t),this.encipher(s),this.S[i][o]=s[0],this.S[i][o+1]=s[1];Fn=0};hr.prototype.enc=function(n,t){for(var e=0;e<t;e++)this.encipher(n.subarray(e*2))};hr.prototype.dec=function(n,t){for(var e=0;e<t;e++)this.decipher(n.subarray(e*2))};var Bs=8,Wo=32;function qo(n,t,e){var r=new hr,s=new Uint32Array(Bs),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<Bs;i++)s[i]=dr(o,o.byteLength);for(i=0;i<64;i++)r.enc(s,s.byteLength/8);for(i=0;i<Bs;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 qm(n,t,e,r,s,i,o){var a=new Uint8Array(64),c=new Uint8Array(64),l=new Uint8Array(Wo),f=new Uint8Array(Wo),u=new Uint8Array(r+4),h,p,A,y,b,x,B=i;if(o<1||t===0||r===0||i===0||i>l.byteLength*l.byteLength||r>1<<20)return-1;for(y=Math.floor((i+l.byteLength-1)/l.byteLength),A=Math.floor((i+y-1)/y),h=0;h<r;h++)u[h]=e[h];for(Qo(a,n,t),x=1;i>0;x++){for(u[r+0]=x>>>24,u[r+1]=x>>>16,u[r+2]=x>>>8,u[r+3]=x,Qo(c,u,r+4),qo(a,c,f),h=l.byteLength;h--;)l[h]=f[h];for(h=1;h<o;h++)for(Qo(c,f,f.byteLength),qo(a,c,f),p=0;p<l.byteLength;p++)l[p]^=f[p];for(A=Math.min(A,i),h=0;h<A&&(b=h*y+(x-1),!(b>=B));h++)s[b]=l[h];i-=h}return 0}Eu.exports={BLOCKS:Bs,HASHSIZE:Wo,hash:qo,pbkdf:qm}});var Qn=lt((xx,Ts)=>{"use strict";var Hn=require("crypto"),Hr;try{Hr=require("cpu-features")()}catch{}var{bindingAvailable:yu,CIPHER_INFO:Km,MAC_INFO:Vm}=Zn(),_u=(()=>{if(typeof Hn.sign=="function"&&typeof Hn.verify=="function"){let n=`-----BEGIN PRIVATE KEY-----\r
3
- MC4CAQAwBQYDK2VwBCIEIHKj+sVa9WcD/q2DJUJaf43Kptc8xYuUQA4bOFj9vC8T\r
4
- -----END PRIVATE KEY-----`,t=Buffer.from("a"),e,r;try{e=Hn.sign(null,t,n),r=Hn.verify(null,t,n,e)}catch{}return Buffer.isBuffer(e)&&e.length===64&&r===!0}return!1})(),Su=typeof Hn.diffieHellman=="function"&&typeof Hn.generateKeyPairSync=="function"&&typeof Hn.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"];Su&&(Ps.unshift("curve25519-sha256"),Ps.unshift("curve25519-sha256@libssh.org"));var zm=Ps.concat(["diffie-hellman-group-exchange-sha1","diffie-hellman-group14-sha1","diffie-hellman-group1-sha1"]),Vo=["ecdsa-sha2-nistp256","ecdsa-sha2-nistp384","ecdsa-sha2-nistp521","rsa-sha2-512","rsa-sha2-256","ssh-rsa"];_u&&Vo.unshift("ssh-ed25519");var Ym=Vo.concat(["ssh-dss"]),bu=(()=>{let n=Hn.getCiphers();return t=>n.includes(Km[t].sslName)})(),Jn=["aes128-gcm@openssh.com","aes256-gcm@openssh.com","aes128-ctr","aes192-ctr","aes256-ctr"];Hr&&Hr.flags&&!Hr.flags.aes?yu?Jn.unshift("chacha20-poly1305@openssh.com"):Jn.push("chacha20-poly1305@openssh.com"):yu&&Hr&&Hr.arch==="x86"?Jn.splice(4,0,"chacha20-poly1305@openssh.com"):Jn.push("chacha20-poly1305@openssh.com");Jn=Jn.filter(bu);var Gm=Jn.concat(["aes256-cbc","aes192-cbc","aes128-cbc","blowfish-cbc","3des-cbc","aes128-gcm","aes256-gcm","arcfour256","arcfour128","cast128-cbc","arcfour"].filter(bu)),xu=(()=>{let n=Hn.getHashes();return t=>n.includes(Vm[t].sslName)})(),wu=["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(xu),jm=wu.concat(["hmac-md5","hmac-sha2-256-96","hmac-sha2-512-96","hmac-ripemd160","hmac-sha1-96","hmac-md5-96"].filter(xu)),Iu=["none","zlib@openssh.com","zlib"],Xm=Iu.concat([]),Fr={BAD_DHGEX:1,OLD_EXIT:2,DYN_RPORT_BUG:4,BUG_DHGEX_LARGE:8,IMPLY_RSA_SHA2_SIGALGS:16};Ts.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:Fr,COMPAT_CHECKS:[["Cisco-1.25",Fr.BAD_DHGEX],[/^Cisco-1[.]/,Fr.BUG_DHGEX_LARGE],[/^[0-9.]+$/,Fr.OLD_EXIT],[/^OpenSSH_5[.][0-9]+/,Fr.DYN_RPORT_BUG],[/^OpenSSH_7[.]4/,Fr.IMPLY_RSA_SHA2_SIGALGS]],DEFAULT_KEX:Ps,SUPPORTED_KEX:zm,DEFAULT_SERVER_HOST_KEY:Vo,SUPPORTED_SERVER_HOST_KEY:Ym,DEFAULT_CIPHER:Jn,SUPPORTED_CIPHER:Gm,DEFAULT_MAC:wu,SUPPORTED_MAC:jm,DEFAULT_COMPRESSION:Iu,SUPPORTED_COMPRESSION:Xm,curve25519Supported:Su,eddsaSupported:_u};Ts.exports.DISCONNECT_REASON_BY_VALUE=Array.from(Object.entries(Ts.exports.DISCONNECT_REASON)).reduce((n,[t,e])=>({...n,[e]:t}),{})});var bn=lt((wx,Nu)=>{"use strict";var En=Si().Ber,Os,ku=Buffer[Symbol.species],Jm=Object.getPrototypeOf(Uint8Array.prototype).fill;function Cu(n,t){return n[t++]*16777216+n[t++]*65536+n[t++]*256+n[t]}function bi(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 xi(n,t,e){return e===void 0&&(e=n.length),new ku(n.buffer,n.byteOffset+t,e-t)}function Yo(){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)?bi(t,r,n,n+=i):t.utf8Slice(n,n+=i):xi(t,n,n+=i)},readRaw:r=>{if(t){if(typeof r!="number")return xi(t,n,n+=t.length-n);if(t.length-n>=r)return xi(t,n,n+=r)}}};return e}function vu(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 zo(n,t,e){return n[e++]=t>>>24,n[e++]=t>>>16,n[e++]=t>>>8,n[e++]=t,e}var Ls=Yo();Nu.exports={bufferCopy:bi,bufferSlice:xi,FastBuffer:ku,bufferFill:(n,t,e,r)=>Jm.call(n,t,e,r),makeError:vu,doFatalError:(n,t,e,r)=>{let s;return Os===void 0&&({DISCONNECT_REASON:Os}=Qn()),t instanceof Error?(s=t,typeof e!="number"?r=Os.PROTOCOL_ERROR:r=e):s=vu(t,e,!0),typeof r!="number"&&(r=Os.PROTOCOL_ERROR),n.disconnect(r),n._destruct(),n._onError(s),1/0},readUInt32BE:Cu,writeUInt32BE:zo,writeUInt32LE:(n,t,e)=>(n[e++]=t,n[e++]=t>>>8,n[e++]=t>>>16,n[e++]=t>>>24,e),makeBufferParser:Yo,bufferParser:Yo(),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=Cu(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)?bi(n,e,t,o):n.utf8Slice(t,o):xi(n,t,o)},sigSSHToASN1:(n,t)=>{switch(t){case"ssh-dss":{if(n.length>40)return n;let e=new En.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,En.Integer),e.writeBuffer(s,En.Integer),e.endSequence(),e.buffer}case"ecdsa-sha2-nistp256":case"ecdsa-sha2-nistp384":case"ecdsa-sha2-nistp521":{Ls.init(n,0);let e=Ls.readString(),r=Ls.readString();if(Ls.clear(),e===void 0||r===void 0)return;let s=new En.Writer;return s.startSequence(),s.writeBuffer(e,En.Integer),s.writeBuffer(r,En.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 En.Reader(n);e.readSequence();let r=e.readString(En.Integer,!0),s=e.readString(En.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 bi(r,a,i,r.length,0),bi(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 En.Reader(n);e.readSequence();let r=e.readString(En.Integer,!0),s=e.readString(En.Integer,!0);if(r===null||s===null)return;let i=Buffer.allocUnsafe(4+r.length+4+s.length);return zo(i,r.length,0),i.set(r,4),zo(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 Bu=lt((Ds,jo)=>{var Go=(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(j,he){r=j,s=he});var i={},o;for(o in e)e.hasOwnProperty(o)&&(i[o]=e[o]);var a=typeof window=="object",c=typeof importScripts=="function",l=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string",f="",u,h,p,A,y;l?(f=c?require("path").dirname(f)+"/":__dirname+"/",u=function(j,he){var xe=Ln(j);return xe?he?xe:xe.toString():(A||(A=require("fs")),y||(y=require("path")),j=y.normalize(j),A.readFileSync(j,he?null:"utf8"))},p=function(j){return j=u(j,!0),j.buffer||(j=new Uint8Array(j)),M(j.buffer),j},h=function(j,he,xe){var Te=Ln(j);Te&&he(Te),A||(A=require("fs")),y||(y=require("path")),j=y.normalize(j),A.readFile(j,function(Je,Lt){Je?xe(Je):he(Lt.buffer)})},1<process.argv.length&&process.argv[1].replace(/\\/g,"/"),process.argv.slice(2),e.inspect=function(){return"[Emscripten Module object]"}):(a||c)&&(c?f=self.location.href:typeof document<"u"&&document.currentScript&&(f=document.currentScript.src),n&&(f=n),f.indexOf("blob:")!==0?f=f.substr(0,f.lastIndexOf("/")+1):f="",u=function(j){try{var he=new XMLHttpRequest;return he.open("GET",j,!1),he.send(null),he.responseText}catch(Je){if(j=Ln(j)){he=[];for(var xe=0;xe<j.length;xe++){var Te=j[xe];255<Te&&(br&&M(!1,"Character code "+Te+" ("+String.fromCharCode(Te)+") at offset "+xe+" not in 0x00-0xFF."),Te&=255),he.push(String.fromCharCode(Te))}return he.join("")}throw Je}},c&&(p=function(j){try{var he=new XMLHttpRequest;return he.open("GET",j,!1),he.responseType="arraybuffer",he.send(null),new Uint8Array(he.response)}catch(xe){if(j=Ln(j))return j;throw xe}}),h=function(j,he,xe){var Te=new XMLHttpRequest;Te.open("GET",j,!0),Te.responseType="arraybuffer",Te.onload=function(){if(Te.status==200||Te.status==0&&Te.response)he(Te.response);else{var Je=Ln(j);Je?he(Je.buffer):xe()}},Te.onerror=xe,Te.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 x;e.wasmBinary&&(x=e.wasmBinary);var B=e.noExitRuntime||!0;typeof WebAssembly!="object"&&K("no native wasm support detected");var H,C=!1;function M(j,he){j||K("Assertion failed: "+he)}function Q(j){var he=e["_"+j];return M(he,"Cannot call unknown function "+j+", make sure it is exported"),he}function N(j,he,xe,Te){var Je={string:function(ct){var $t=0;if(ct!=null&&ct!==0){var Mt=(ct.length<<2)+1;$t=li(Mt);var Ct=$t,gt=k;if(0<Mt){Mt=Ct+Mt-1;for(var pn=0;pn<ct.length;++pn){var vt=ct.charCodeAt(pn);if(55296<=vt&&57343>=vt){var lr=ct.charCodeAt(++pn);vt=65536+((vt&1023)<<10)|lr&1023}if(127>=vt){if(Ct>=Mt)break;gt[Ct++]=vt}else{if(2047>=vt){if(Ct+1>=Mt)break;gt[Ct++]=192|vt>>6}else{if(65535>=vt){if(Ct+2>=Mt)break;gt[Ct++]=224|vt>>12}else{if(Ct+3>=Mt)break;gt[Ct++]=240|vt>>18,gt[Ct++]=128|vt>>12&63}gt[Ct++]=128|vt>>6&63}gt[Ct++]=128|vt&63}}gt[Ct]=0}}return $t},array:function(ct){var $t=li(ct.length);return v.set(ct,$t),$t}},Lt=Q(j),vn=[];if(j=0,Te)for(var ln=0;ln<Te.length;ln++){var vr=Je[xe[ln]];vr?(j===0&&(j=ci()),vn[ln]=vr(Te[ln])):vn[ln]=Te[ln]}return xe=Lt.apply(null,vn),xe=(function(ct){if(he==="string")if(ct){for(var $t=k,Mt=ct+NaN,Ct=ct;$t[Ct]&&!(Ct>=Mt);)++Ct;if(16<Ct-ct&&$t.subarray&&S)ct=S.decode($t.subarray(ct,Ct));else{for(Mt="";ct<Ct;){var gt=$t[ct++];if(gt&128){var pn=$t[ct++]&63;if((gt&224)==192)Mt+=String.fromCharCode((gt&31)<<6|pn);else{var vt=$t[ct++]&63;gt=(gt&240)==224?(gt&15)<<12|pn<<6|vt:(gt&7)<<18|pn<<12|vt<<6|$t[ct++]&63,65536>gt?Mt+=String.fromCharCode(gt):(gt-=65536,Mt+=String.fromCharCode(55296|gt>>10,56320|gt&1023))}}else Mt+=String.fromCharCode(gt)}ct=Mt}}else ct="";else ct=he==="boolean"?!!ct:ct;return ct})(xe),j!==0&&ss(j),xe}var S=typeof TextDecoder<"u"?new TextDecoder("utf8"):void 0,w,v,k;function P(){var j=H.buffer;w=j,e.HEAP8=v=new Int8Array(j),e.HEAP16=new Int16Array(j),e.HEAP32=new Int32Array(j),e.HEAPU8=k=new Uint8Array(j),e.HEAPU16=new Uint16Array(j),e.HEAPU32=new Uint32Array(j),e.HEAPF32=new Float32Array(j),e.HEAPF64=new Float64Array(j)}var ne,Y=[],G=[],te=[];function le(){var j=e.preRun.shift();Y.unshift(j)}var U=0,R=null,O=null;e.preloadedImages={},e.preloadedAudios={};function K(j){throw e.onAbort&&e.onAbort(j),b(j),C=!0,j=new WebAssembly.RuntimeError("abort("+j+"). Build with -s ASSERTIONS=1 for more info."),s(j),j}var ee="data:application/octet-stream;base64,",ue;if(ue="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==",!ue.startsWith(ee)){var ie=ue;ue=e.locateFile?e.locateFile(ie,f):f+ie}function Xe(){var j=ue;try{if(j==ue&&x)return new Uint8Array(x);var he=Ln(j);if(he)return he;if(p)return p(j);throw"both async and sync fetching of the wasm failed"}catch(xe){K(xe)}}function dt(){if(!x&&(a||c)){if(typeof fetch=="function"&&!ue.startsWith("file://"))return fetch(ue,{credentials:"same-origin"}).then(function(j){if(!j.ok)throw"failed to load wasm binary file at '"+ue+"'";return j.arrayBuffer()}).catch(function(){return Xe()});if(h)return new Promise(function(j,he){h(ue,function(xe){j(new Uint8Array(xe))},he)})}return Promise.resolve().then(function(){return Xe()})}function cn(j){for(;0<j.length;){var he=j.shift();if(typeof he=="function")he(e);else{var xe=he.m;typeof xe=="number"?he.l===void 0?ne.get(xe)():ne.get(xe)(he.l):xe(he.l===void 0?null:he.l)}}}var br=!1,xr=typeof atob=="function"?atob:function(j){var he="",xe=0;j=j.replace(/[^A-Za-z0-9\+\/=]/g,"");do{var Te="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(j.charAt(xe++)),Je="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(j.charAt(xe++)),Lt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(j.charAt(xe++)),vn="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(j.charAt(xe++));Te=Te<<2|Je>>4,Je=(Je&15)<<4|Lt>>2;var ln=(Lt&3)<<6|vn;he+=String.fromCharCode(Te),Lt!==64&&(he+=String.fromCharCode(Je)),vn!==64&&(he+=String.fromCharCode(ln))}while(xe<j.length);return he};function Ln(j){if(j.startsWith(ee)){if(j=j.slice(ee.length),typeof l=="boolean"&&l){var he=Buffer.from(j,"base64");he=new Uint8Array(he.buffer,he.byteOffset,he.byteLength)}else try{var xe=xr(j),Te=new Uint8Array(xe.length);for(j=0;j<xe.length;++j)Te[j]=xe.charCodeAt(j);he=Te}catch{throw Error("Converting base64 string to bytes failed.")}return he}}var wr={a:function(j){var he=k.length;if(j>>>=0,2147483648<j)return!1;for(var xe=1;4>=xe;xe*=2){var Te=he*(1+.2/xe);Te=Math.min(Te,j+100663296),Te=Math.max(j,Te),0<Te%65536&&(Te+=65536-Te%65536);e:{try{H.grow(Math.min(2147483648,Te)-w.byteLength+65535>>>16),P();var Je=1;break e}catch{}Je=void 0}if(Je)return!0}return!1}};(function(){function j(Je){e.asm=Je.exports,H=e.asm.b,P(),ne=e.asm.j,G.unshift(e.asm.c),U--,e.monitorRunDependencies&&e.monitorRunDependencies(U),U==0&&(R!==null&&(clearInterval(R),R=null),O&&(Je=O,O=null,Je()))}function he(Je){j(Je.instance)}function xe(Je){return dt().then(function(Lt){return WebAssembly.instantiate(Lt,Te)}).then(Je,function(Lt){b("failed to asynchronously prepare wasm: "+Lt),K(Lt)})}var Te={a:wr};if(U++,e.monitorRunDependencies&&e.monitorRunDependencies(U),e.instantiateWasm)try{return e.instantiateWasm(Te,j)}catch(Je){return b("Module.instantiateWasm callback failed with error: "+Je),!1}return(function(){return x||typeof WebAssembly.instantiateStreaming!="function"||ue.startsWith(ee)||ue.startsWith("file://")||typeof fetch!="function"?xe(he):fetch(ue,{credentials:"same-origin"}).then(function(Je){return WebAssembly.instantiateStreaming(Je,Te).then(he,function(Lt){return b("wasm streaming compile failed: "+Lt),b("falling back to ArrayBuffer instantiation"),xe(he)})})})().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 ci=e.stackSave=function(){return(ci=e.stackSave=e.asm.e).apply(null,arguments)},ss=e.stackRestore=function(){return(ss=e.stackRestore=e.asm.f).apply(null,arguments)},li=e.stackAlloc=function(){return(li=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(j,he,xe,Te){xe=xe||[];var Je=xe.every(function(Lt){return Lt==="number"});return he!=="string"&&Je&&!Te?Q(j):function(){return N(j,he,xe,arguments)}};var Ir;O=function j(){Ir||Cr(),Ir||(O=j)};function Cr(){function j(){if(!Ir&&(Ir=!0,e.calledRun=!0,!C)){if(cn(G),r(e),e.onRuntimeInitialized&&e.onRuntimeInitialized(),e.postRun)for(typeof e.postRun=="function"&&(e.postRun=[e.postRun]);e.postRun.length;){var he=e.postRun.shift();te.unshift(he)}cn(te)}}if(!(0<U)){if(e.preRun)for(typeof e.preRun=="function"&&(e.preRun=[e.preRun]);e.preRun.length;)le();cn(Y),0<U||(e.setStatus?(e.setStatus("Running..."),setTimeout(function(){setTimeout(function(){e.setStatus("")},1),j()},1)):j())}}if(e.run=Cr,e.preInit)for(typeof e.preInit=="function"&&(e.preInit=[e.preInit]);0<e.preInit.length;)e.preInit.pop()();return Cr(),t.ready})})();typeof Ds=="object"&&typeof jo=="object"?jo.exports=Go:typeof define=="function"&&define.amd?define([],function(){return Go}):typeof Ds=="object"&&(Ds.createPoly1305=Go)});var Zn=lt((Ix,Lu)=>{"use strict";var{createCipheriv:Wr,createDecipheriv:Ms,createHmac:Xo,randomFillSync:pr,timingSafeEqual:Jo}=require("crypto"),{readUInt32BE:Ii,writeUInt32BE:dn}=bn(),er=Buffer[Symbol.species],Ru=2**32-1,Pu=Buffer.alloc(0),Qr=Buffer.alloc(4),Us=new Map,mr=35e3,Zo,pa,ma,ga,Aa,Ea,ya;try{Zo=require("./crypto/build/Release/sshcrypto.node"),{AESGCMCipher:pa,ChaChaPolyCipher:ma,GenericCipher:ga,AESGCMDecipher:Aa,ChaChaPolyDecipher:Ea,GenericDecipher:ya}=Zo}catch{}var qt=1,Zm=(()=>{function n(t,e,r,s,i,o,a){return{sslName:t,blockLen:e,keyLen:r,ivLen:s!==0||a&qt?s:e,authLen:i,discardLen:o,stream:!!(a&qt)}}return{"chacha20-poly1305@openssh.com":n("chacha20",8,64,0,16,0,qt),"aes128-gcm":n("aes-128-gcm",16,16,12,16,0,qt),"aes256-gcm":n("aes-256-gcm",16,32,12,16,0,qt),"aes128-gcm@openssh.com":n("aes-128-gcm",16,16,12,16,0,qt),"aes256-gcm@openssh.com":n("aes-256-gcm",16,32,12,16,0,qt),"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,qt),"aes192-ctr":n("aes-192-ctr",16,24,16,0,0,qt),"aes256-ctr":n("aes-256-ctr",16,32,16,0,0,qt),"3des-ctr":n("des-ede3",8,24,8,0,0,qt),"blowfish-ctr":n("bf-ecb",8,16,8,0,0,qt),"cast128-ctr":n("cast5-ecb",8,16,8,0,0,qt),arcfour:n("rc4",8,16,0,0,1536,qt),arcfour128:n("rc4",8,16,0,0,1536,qt),arcfour256:n("rc4",8,32,0,0,1536,qt),arcfour512:n("rc4",8,64,0,0,1536,qt)}})(),eg=(()=>{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)}})(),ea=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 dn(s,e-4,0),s[4]=r,pr(s,5+t,r),s}encrypt(t){this._dead||(this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},Tu=Buffer.alloc(32),rn=Buffer.alloc(16),wi,Ci,_a,ta=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 dn(s,e-4,0),s[4]=r,pr(s,5+t,r),s}encrypt(t){if(this._dead)return;rn[0]=0,dn(rn,this.outSeqno,12);let e=Wr("chacha20",this._encKeyMain,rn).update(Tu),r=Wr("chacha20",this._encKeyPktLen,rn).update(t.slice(0,4));this._onWrite(r),rn[0]=1;let s=Wr("chacha20",this._encKeyMain,rn).update(t.slice(4));this._onWrite(s),_a(Ci,r,r.length,s,s.length,e);let i=Buffer.allocUnsafe(16);i.set(new Uint8Array(wi.HEAPU8.buffer,Ci,16),0),this._onWrite(i),this.outSeqno=this.outSeqno+1>>>0}},na=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._instance=new ma(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 dn(s,e-4,0),s[4]=r,pr(s,5+t,r),s}encrypt(t){this._dead||(this._instance.encrypt(t,this.outSeqno),this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},ra=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 dn(s,e-4,0),s[4]=r,pr(s,5+t,r),s}encrypt(t){if(this._dead)return;let e=Wr(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),Ou(this._encIV),this.outSeqno=this.outSeqno+1>>>0}},ia=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._instance=new pa(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 dn(s,e-4,0),s[4]=r,pr(s,5+t,r),s}encrypt(t){this._dead||(this._instance.encrypt(t),this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},sa=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._encBlockLen=e.cipherInfo.blockLen,this._cipherInstance=Wr(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=Us.get(r);s===void 0&&(s=Buffer.alloc(r),Us.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 dn(i,r-4,0),i[4]=s,pr(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=Xo(this._macSSLName,this._macKey),dn(Qr,this.outSeqno,0),e.update(Qr),e.update(s),e.update(i)}else{let s=this._cipherInstance.update(t);this._onWrite(s),e=Xo(this._macSSLName,this._macKey),dn(Qr,this.outSeqno,0),e.update(Qr),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}},oa=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 ga(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 dn(i,r-4,0),i[4]=s,pr(i,5+t,s),i}encrypt(t){this._dead||(this._instance.encrypt(t,this.outSeqno),this._macActualLen<this._macLen&&(t=new er(t.buffer,t.byteOffset,t.length-(this._macLen-this._macActualLen))),this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},aa=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>mr||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 er(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1):Pu;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}}}},ca=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;rn[0]=0,dn(rn,this.inSeqno,12);let c=Ms("chacha20",this._decKeyPktLen,rn).update(this._lenBuf);if(this._len=Ii(c,0),this._len>mr||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}rn[0]=0,dn(rn,this.inSeqno,12);let s=Wr("chacha20",this._decKeyMain,rn).update(Tu);if(_a(Ci,this._lenBuf,4,this._packet,this._packet.length,s),this._calcMac.set(new Uint8Array(wi.HEAPU8.buffer,Ci,16),0),!Jo(this._calcMac,this._mac))throw new Error("Invalid MAC");rn[0]=1;let i=Ms("chacha20",this._decKeyMain,rn).update(this._packet),o=new er(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}}}},la=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._instance=new Ea(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>mr||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 er(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}}}},fa=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>mr||this._len<16||(this._len&15)!==0)throw new Error("Bad packet length");this._decipherInstance=Ms(this._decipherSSLName,this._decipherKey,this._decipherIV),this._decipherInstance.setAutoPadding(!1),this._decipherInstance.setAAD(tg(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 er(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1):Pu;this.inSeqno=this.inSeqno+1>>>0,Ou(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}}}},ua=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._instance=new Aa(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>mr||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 er(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}}}},da=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._decipherInstance=Ms(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=Us.get(r);s===void 0&&(s=Buffer.alloc(r),Us.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=Ii(this._block,0):(a=this._decipherInstance.update(this._block),this._len=Ii(a,0),c=4+this._len-this._blockSize),this._len>mr||this._len<5||(c&this._blockSize-1)!==0)throw new Error("Bad packet length");if(this._macInstance=Xo(this._macSSLName,this._macKey),dn(Qr,this.inSeqno,0),this._macInstance.update(Qr),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)),!ng(s,this._mac))throw new Error("Invalid MAC");let i=new er(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}}}},ha=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._instance=new ya(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=Ii(this._block,0):(this._instance.decryptBlock(this._block),this._len=Ii(this._block,0),o=4+this._len-this._block.length),this._len>mr||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 er(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 Ou(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 tg=(()=>{let n=Buffer.alloc(4);return t=>(n[0]=t>>>24,n[1]=t>>>16,n[2]=t>>>8,n[3]=t,n)})();function ng(n,t){return n.length!==t.length?(Jo(n,n),!1):Jo(n,t)}function rg(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>Ru)throw new Error("Invalid outbound.seqno");let e=!!t.forceNative;switch(t.cipherInfo.sslName){case"aes-128-gcm":case"aes-256-gcm":return pa&&!e?new ia(n):new ra(n);case"chacha20":return ma&&!e?new na(n):new ta(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 ga&&!e?new oa(n):new sa(n)}}}function ig(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>Ru)throw new Error("Invalid inbound.seqno");let e=!!t.forceNative;switch(t.decipherInfo.sslName){case"aes-128-gcm":case"aes-256-gcm":return Aa&&!e?new ua(n):new fa(n);case"chacha20":return Ea&&!e?new la(n):new ca(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 ya&&!e?new ha(n):new da(n)}}}Lu.exports={CIPHER_INFO:Zm,MAC_INFO:eg,bindingAvailable:!!Zo,init:new Promise(async(n,t)=>{try{wi=await Bu()(),Ci=wi._malloc(16),_a=wi.cwrap("poly1305_auth",null,["number","array","number","array","number","array"])}catch(e){return t(e)}n()}),NullCipher:ea,createCipher:rg,NullDecipher:aa,createDecipher:ig}});var nr=lt((Cx,Ku)=>{"use strict";var{createDecipheriv:ba,createECDH:sg,createHash:ki,createHmac:og,createSign:ag,createVerify:cg,getCiphers:lg,sign:Du,verify:Mu}=require("crypto"),fg=lg(),{Ber:Re}=Si(),ug=Ko().pbkdf,{CIPHER_INFO:Ni}=Zn(),{eddsaSupported:xa,SUPPORTED_CIPHER:dg}=Qn(),{bufferSlice:gr,makeBufferParser:hg,readString:ke,readUInt32BE:vi,writeUInt32BE:Ht}=bn(),Wn=Symbol("Hash Algorithm"),xn=Symbol("Private key PEM"),Rn=Symbol("Public key PEM"),tr=Symbol("Public key SSH"),qr=Symbol("Decrypted Key"),Sa=Object.create(null);{let n=Object.keys(Ni);for(let t=0;t<n.length;++t){let e=Ni[n[t]].sslName;!e||Sa[e]||(Sa[e]=Ni[n[t]])}}var $s=hg();function wn(n,t){t=t.base64Slice(0,t.length);let e=t.replace(/.{64}/g,`$&
5
- `);return t.length&63&&(e+=`
6
- `),`-----BEGIN ${n} KEY-----
7
- ${e}-----END ${n} KEY-----`}function Bi(n,t){let e=Buffer.allocUnsafe(n.length+t.length);return e.set(n,0),e.set(t,n.length),e}function wa(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=vi(n,r);if(i<4+o)return!1;r+=4+o}return n._pos=r,!0}function Ri(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(),wn("PUBLIC",e.buffer)}function Pi(n,t){let e=Buffer.allocUnsafe(15+t.length+4+n.length);Ht(e,7,0),e.utf8Write("ssh-rsa",4,7);let r=11;return Ht(e,t.length,r),e.set(t,r+=4),Ht(e,n.length,r+=t.length),e.set(n,r+4),e}var Uu=(()=>{function n(r,s,i,o,a,c,l,f){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(l,Re.Integer),u.writeBuffer(f,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,l){let f=t(o),u=e(f%(t(c)-1n)),h=e(f%(t(l)-1n));return wn("RSA PRIVATE",n(s,i,o,c,l,u,h,a))}})();function Ti(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(),wn("PUBLIC",s.buffer)}function Oi(n,t,e,r){let s=Buffer.allocUnsafe(15+n.length+4+t.length+4+e.length+4+r.length);Ht(s,7,0),s.utf8Write("ssh-dss",4,7);let i=11;return Ht(s,n.length,i),s.set(n,i+=4),Ht(s,t.length,i+=n.length),s.set(t,i+=4),Ht(s,e.length,i+=t.length),s.set(e,i+=4),Ht(s,r.length,i+=e.length),s.set(r,i+4),s}function $u(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(),wn("DSA PRIVATE",i.buffer)}function Fu(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(),wn("PUBLIC",t.buffer)}function Hu(n){let t=Buffer.allocUnsafe(19+n.length);return Ht(t,11,0),t.utf8Write("ssh-ed25519",4,11),Ht(t,n.length,15),t.set(n,19),t}function pg(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(),wn("PRIVATE",t.buffer)}function Ia(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(),wn("PUBLIC",e.buffer)}function Ca(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 Ht(r,19,0),r.utf8Write(`ecdsa-sha2-${e}`,4,19),Ht(r,8,23),r.utf8Write(e,27,8),Ht(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(),wn("EC PRIVATE",r.buffer)}function gg(n,t){let e=sg(n);return e.setPrivateKey(t),e.getPublicKey()}var Li={sign:typeof Du=="function"?function(t,e){let r=this[xn];if(r===null)return new Error("No private key available");(!e||typeof e!="string")&&(e=this[Wn]);try{return Du(e,t,r)}catch(s){return s}}:function(t,e){let r=this[xn];if(r===null)return new Error("No private key available");(!e||typeof e!="string")&&(e=this[Wn]);let s=ag(e);s.update(t);try{return s.sign(r)}catch(i){return i}},verify:typeof Mu=="function"?function(t,e,r){let s=this[Rn];if(s===null)return new Error("No public key available");(!r||typeof r!="string")&&(r=this[Wn]);try{return Mu(r,t,s,e)}catch(i){return i}}:function(t,e,r){let s=this[Rn];if(s===null)return new Error("No public key available");(!r||typeof r!="string")&&(r=this[Wn]);let i=cg(r);i.update(t);try{return i.verify(s,e)}catch(o){return o}},isPrivateKey:function(){return this[xn]!==null},getPrivatePEM:function(){return this[xn]},getPublicPEM:function(){return this[Rn]},getPublicSSH:function(){return this[tr]},equals:function(t){let e=qu(t);return e instanceof Error?!1:this.type===e.type&&this[xn]===e[xn]&&this[Rn]===e[Rn]&&this[tr].equals(e[tr])}};function Fs(n,t,e,r,s,i,o){this.type=n,this.comment=t,this[xn]=e,this[Rn]=r,this[tr]=s,this[Wn]=i,this[qr]=o}Fs.prototype=Li;{let t=function(e,r,s){let i=[];if(e.length<8)return new Error("Malformed OpenSSH private key");let o=vi(e,0),a=vi(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,l;for(c=0;c<r;++c){let u,h,p,A,y=ke(e,e._pos,!0);if(y===void 0)return new Error("Malformed OpenSSH private key");switch(y){case"ssh-rsa":{let x=ke(e,e._pos);if(x===void 0)return new Error("Malformed OpenSSH private key");let B=ke(e,e._pos);if(B===void 0)return new Error("Malformed OpenSSH private key");let H=ke(e,e._pos);if(H===void 0)return new Error("Malformed OpenSSH private key");let C=ke(e,e._pos);if(C===void 0)return new Error("Malformed OpenSSH private key");let M=ke(e,e._pos);if(M===void 0)return new Error("Malformed OpenSSH private key");let Q=ke(e,e._pos);if(Q===void 0)return new Error("Malformed OpenSSH private key");p=Ri(x,B),A=Pi(x,B),h=Uu(x,B,H,C,M,Q),u="sha1";break}case"ssh-dss":{let x=ke(e,e._pos);if(x===void 0)return new Error("Malformed OpenSSH private key");let B=ke(e,e._pos);if(B===void 0)return new Error("Malformed OpenSSH private key");let H=ke(e,e._pos);if(H===void 0)return new Error("Malformed OpenSSH private key");let C=ke(e,e._pos);if(C===void 0)return new Error("Malformed OpenSSH private key");let M=ke(e,e._pos);if(M===void 0)return new Error("Malformed OpenSSH private key");p=Ti(x,B,H,C),A=Oi(x,B,H,C),h=$u(x,B,H,C,M),u="sha1";break}case"ssh-ed25519":{if(!xa)return new Error(`Unsupported OpenSSH private key type: ${y}`);let x=ke(e,e._pos);if(x===void 0||x.length!==32)return new Error("Malformed OpenSSH private key");let B=ke(e,e._pos);if(B===void 0||B.length!==64)return new Error("Malformed OpenSSH private key");p=Fu(x),A=Hu(x),h=pg(gr(B,0,32)),u=null;break}case"ecdsa-sha2-nistp256":u="sha256",l="1.2.840.10045.3.1.7";case"ecdsa-sha2-nistp384":u===void 0&&(u="sha384",l="1.3.132.0.34");case"ecdsa-sha2-nistp521":{if(u===void 0&&(u="sha512",l="1.3.132.0.35"),!wa(e,1))return new Error("Malformed OpenSSH private key");let x=ke(e,e._pos);if(x===void 0)return new Error("Malformed OpenSSH private key");let B=ke(e,e._pos);if(B===void 0)return new Error("Malformed OpenSSH private key");p=Ia(l,x),A=Ca(l,x),h=mg(l,x,B);break}default:return new Error(`Unsupported OpenSSH private key type: ${y}`)}let b=ke(e,e._pos,!0);if(b===void 0)return new Error("Malformed OpenSSH private key");i.push(new Fs(y,b,h,p,A,u,s))}let f=0;for(c=e._pos;c<e.length;++c)if(e[c]!==++f%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-----$/;Fs.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=ke(o,15,!0);if(c===void 0)return new Error("Malformed OpenSSH private key");if(c!=="none"&&dg.indexOf(c)===-1)return new Error(`Unsupported cipher for OpenSSH key: ${c}`);let l=ke(o,o._pos,!0);if(l===void 0)return new Error("Malformed OpenSSH private key");if(l!=="none"){if(c==="none")return new Error("Malformed OpenSSH private key");if(l!=="bcrypt")return new Error(`Unsupported kdf name for OpenSSH key: ${l}`);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 f,u,h;c!=="none"&&(f=Ni[c]);let p=ke(o,o._pos);if(p===void 0)return new Error("Malformed OpenSSH private key");if(p.length)switch(l){case"none":return new Error("Malformed OpenSSH private key");case"bcrypt":{let y=ke(p,0);if(y===void 0||p._pos+4>p.length)return new Error("Malformed OpenSSH private key");let b=vi(p,p._pos),x=Buffer.allocUnsafe(f.keyLen+f.ivLen);if(ug(r,r.length,y,y.length,x,x.length,b)!==0)return new Error("Failed to generate information to decrypt key");u=gr(x,0,f.keyLen),h=gr(x,f.keyLen,x.length);break}}else if(l!=="none")return new Error("Malformed OpenSSH private key");if(o._pos+3>=o.length)return new Error("Malformed OpenSSH private key");let A=vi(o,o._pos);if(o._pos+=4,A>0){for(let b=0;b<A;++b){let x=ke(o,o._pos);if(x===void 0)return new Error("Malformed OpenSSH private key");if(ke(x,0,!0)===void 0)return new Error("Malformed OpenSSH private key")}let y=ke(o,o._pos);if(y===void 0)return new Error("Malformed OpenSSH private key");if(u!==void 0){if(y.length<f.blockLen||y.length%f.blockLen!==0)return new Error("Malformed OpenSSH private key");try{let b={authTagLength:f.authLen},x=ba(f.sslName,u,h,b);if(x.setAutoPadding(!1),f.authLen>0){if(o.length-o._pos<f.authLen)return new Error("Malformed OpenSSH private key");x.setAuthTag(gr(o,o._pos,o._pos+=f.authLen))}y=Bi(x.update(y),x.final())}catch(b){return b}}if(o._pos!==o.length)return new Error("Malformed OpenSSH private key");i=t(y,A,u!==void 0)}else i=[];return i instanceof Error?i:i[0]}}function Hs(n,t,e,r,s,i,o){this.type=n,this.comment=t,this[xn]=e,this[Rn]=r,this[tr]=s,this[Wn]=i,this[qr]=o}Hs.prototype=Li;{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-----$/;Hs.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 A=0;A<i.length;++A){let y=i[A],b=y.indexOf(":");if(y.slice(0,b)==="DEK-Info"){let x=y.slice(b+2);if(b=x.indexOf(","),b===-1)continue;let B=x.slice(0,b).toLowerCase();if(fg.indexOf(B)===-1)return new Error(`Cipher (${B}) not supported for encrypted OpenSSH private key`);let H=Sa[B];if(!H)return new Error(`Cipher (${B}) not supported for encrypted OpenSSH private key`);let C=Buffer.from(x.slice(b+1),"hex");if(C.length!==H.ivLen)return new Error("Malformed encrypted OpenSSH private key");if(!e)return new Error("Encrypted OpenSSH private key detected, but no passphrase given");let M=gr(C,0,8),Q=ki("md5").update(e).update(M).digest();for(;Q.length<H.keyLen;)Q=Bi(Q,ki("md5").update(Q).update(e).update(M).digest());Q.length>H.keyLen&&(Q=gr(Q,0,H.keyLen));try{let N=ba(B,Q,C);N.setAutoPadding(!1),s=Bi(N.update(s),N.final()),o=!0}catch(N){return N}}}}let a,c,l,f,u,h,p="Malformed OpenSSH private key";switch(o&&(p+=". Bad passphrase?"),r[1]){case"RSA":a="ssh-rsa",c=wn("RSA PRIVATE",s);try{h=new Re.Reader(s),h.readSequence(),h.readInt();let A=h.readString(Re.Integer,!0);if(A===null)return new Error(p);let y=h.readString(Re.Integer,!0);if(y===null)return new Error(p);l=Ri(A,y),f=Pi(A,y)}catch{return new Error(p)}u="sha1";break;case"DSA":a="ssh-dss",c=wn("DSA PRIVATE",s);try{h=new Re.Reader(s),h.readSequence(),h.readInt();let A=h.readString(Re.Integer,!0);if(A===null)return new Error(p);let y=h.readString(Re.Integer,!0);if(y===null)return new Error(p);let b=h.readString(Re.Integer,!0);if(b===null)return new Error(p);let x=h.readString(Re.Integer,!0);if(x===null)return new Error(p);l=Ti(A,y,b,x),f=Oi(A,y,b,x)}catch{return new Error(p)}u="sha1";break;case"EC":{let A,y,b;try{h=new Re.Reader(s),h.readSequence(),h.readInt(),y=h.readString(Re.OctetString,!0),h.readByte();let B=h.readLength();if(B!==null){if(h._offset=B,b=h.readOID(),b===null)return new Error(p);switch(b){case"1.2.840.10045.3.1.7":A="prime256v1",a="ecdsa-sha2-nistp256",u="sha256";break;case"1.3.132.0.34":A="secp384r1",a="ecdsa-sha2-nistp384",u="sha384";break;case"1.3.132.0.35":A="secp521r1",a="ecdsa-sha2-nistp521",u="sha512";break;default:return new Error(`Unsupported private key EC OID: ${b}`)}}else return new Error(p)}catch{return new Error(p)}c=wn("EC PRIVATE",s);let x=gg(A,y);l=Ia(b,x),f=Ca(b,x);break}}return new Hs(a,"",c,l,f,u,o)}}function Qs(n,t,e,r,s,i,o){this.type=n,this.comment=t,this[xn]=e,this[Rn]=r,this[tr]=s,this[Wn]=i,this[qr]=o}Qs.prototype=Li;{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]+)/;Qs.parse=(i,o)=>{let a=s.exec(i);if(a===null)return null;let c=a[2],l=c!=="none";if(l&&!o)return new Error("Encrypted PPK private key detected, but no passphrase given");let f=Buffer.from(a[5],"base64");if(l){let v=Ni[c],k=Bi(ki("sha1").update(e).update(o).digest(),ki("sha1").update(r).update(o).digest());k.length>v.keyLen&&(k=gr(k,0,v.keyLen));try{let P=ba(v.sslName,k,t);P.setAutoPadding(!1),f=Bi(P.update(f),P.final())}catch(P){return P}}let u=a[1],h=a[3],p=Buffer.from(a[4],"base64"),A=a[6],y=u.length,b=c.length,x=Buffer.byteLength(h),B=p.length,H=f.length,C=Buffer.allocUnsafe(4+y+4+b+4+x+4+B+4+H),M=0;if(Ht(C,y,M),C.utf8Write(u,M+=4,y),Ht(C,b,M+=y),C.utf8Write(c,M+=4,b),Ht(C,x,M+=b),C.utf8Write(h,M+=4,x),Ht(C,B,M+=x),C.set(p,M+=4),Ht(C,H,M+=B),C.set(f,M+4),o||(o=n),og("sha1",ki("sha1").update("putty-private-key-file-mac-key").update(o).digest()).update(C).digest("hex")!==A)return l?new Error("PPK private key integrity check failed -- bad passphrase?"):new Error("PPK private key integrity check failed");let N,S,w;switch(p._pos=0,wa(p,1),u){case"ssh-rsa":{let v=ke(p,p._pos);if(v===void 0)return new Error("Malformed PPK public key");let k=ke(p,p._pos);if(k===void 0)return new Error("Malformed PPK public key");let P=ke(f,0);if(P===void 0)return new Error("Malformed PPK private key");let ne=ke(f,f._pos);if(ne===void 0)return new Error("Malformed PPK private key");let Y=ke(f,f._pos);if(Y===void 0)return new Error("Malformed PPK private key");let G=ke(f,f._pos);if(G===void 0)return new Error("Malformed PPK private key");N=Ri(k,v),S=Pi(k,v),w=Uu(k,v,P,G,ne,Y);break}case"ssh-dss":{let v=ke(p,p._pos);if(v===void 0)return new Error("Malformed PPK public key");let k=ke(p,p._pos);if(k===void 0)return new Error("Malformed PPK public key");let P=ke(p,p._pos);if(P===void 0)return new Error("Malformed PPK public key");let ne=ke(p,p._pos);if(ne===void 0)return new Error("Malformed PPK public key");let Y=ke(f,0);if(Y===void 0)return new Error("Malformed PPK private key");N=Ti(v,k,P,ne),S=Oi(v,k,P,ne),w=$u(v,k,P,ne,Y);break}}return new Qs(u,h,w,N,S,"sha1",l)}}function qs(n,t,e,r,s){this.type=n,this.comment=t,this[xn]=null,this[Rn]=e,this[tr]=r,this[Wn]=s,this[qr]=!1}qs.prototype=Li;{let n;xa?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].*)?)$/,qs.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=ke(i,i._pos,!0);return a===void 0||a.indexOf(s)!==0?new Error("Malformed OpenSSH public key"):va(i,s,o,r)}}function Ws(n,t,e,r,s){this.type=n,this.comment=t,this[xn]=null,this[Rn]=e,this[tr]=r,this[Wn]=s,this[qr]=!1}Ws.prototype=Li;{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;Ws.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 p=i[1],A=i[2].replace(r,"");if(A.length>1024)return e.lastIndex=0,new Error("Malformed RFC4716 public key");a=e.lastIndex,p.toLowerCase()==="comment"&&(c=A,c.length>1&&c.charCodeAt(0)===34&&c.charCodeAt(c.length-1)===34&&(c=c.slice(1,-1)))}let l=o.slice(a);if(!t.test(l))return new Error("Malformed RFC4716 public key");l=Buffer.from(l,"base64");let f=ke(l,0,!0);if(f===void 0)return new Error("Malformed RFC4716 public key");let u=null,h=null;switch(f){case"ssh-rsa":{let p=ke(l,l._pos);if(p===void 0)return new Error("Malformed RFC4716 public key");let A=ke(l,l._pos);if(A===void 0)return new Error("Malformed RFC4716 public key");u=Ri(A,p),h=Pi(A,p);break}case"ssh-dss":{let p=ke(l,l._pos);if(p===void 0)return new Error("Malformed RFC4716 public key");let A=ke(l,l._pos);if(A===void 0)return new Error("Malformed RFC4716 public key");let y=ke(l,l._pos);if(y===void 0)return new Error("Malformed RFC4716 public key");let b=ke(l,l._pos);if(b===void 0)return new Error("Malformed RFC4716 public key");u=Ti(p,A,y,b),h=Oi(p,A,y,b);break}default:return new Error("Malformed RFC4716 public key")}return new Ws(f,c,u,h,"sha1")}}function va(n,t,e,r){if(!Qu(t))return new Error(`Unsupported OpenSSH public key type: ${t}`);let s,i,o=null,a=null;switch(t){case"ssh-rsa":{let c=ke(n,n._pos||0);if(c===void 0)return new Error("Malformed OpenSSH public key");let l=ke(n,n._pos);if(l===void 0)return new Error("Malformed OpenSSH public key");o=Ri(l,c),a=Pi(l,c),s="sha1";break}case"ssh-dss":{let c=ke(n,n._pos||0);if(c===void 0)return new Error("Malformed OpenSSH public key");let l=ke(n,n._pos);if(l===void 0)return new Error("Malformed OpenSSH public key");let f=ke(n,n._pos);if(f===void 0)return new Error("Malformed OpenSSH public key");let u=ke(n,n._pos);if(u===void 0)return new Error("Malformed OpenSSH public key");o=Ti(c,l,f,u),a=Oi(c,l,f,u),s="sha1";break}case"ssh-ed25519":{let c=ke(n,n._pos||0);if(c===void 0||c.length!==32)return new Error("Malformed OpenSSH public key");o=Fu(c),a=Hu(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"),!wa(n,1))return new Error("Malformed OpenSSH public key");let c=ke(n,n._pos||0);if(c===void 0)return new Error("Malformed OpenSSH public key");o=Ia(i,c),a=Ca(i,c);break}default:return new Error(`Unsupported OpenSSH public key type: ${t}`)}return new qs(r,e,o,a,s)}function Qu(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(xa)return!0;default:return!1}}function Wu(n){return n?typeof n[qr]=="boolean":!1}function qu(n,t){if(Wu(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=Fs.parse(n,t))!==null||(r=Hs.parse(n,t))!==null||(r=Qs.parse(n,t))!==null||(r=qs.parse(n))!==null||(r=Ws.parse(n))!==null)return r;if(e){$s.init(e,0);let s=$s.readString(!0);s!==void 0&&(n=$s.readRaw(),n!==void 0&&(r=va(n,s,"",s),r instanceof Error&&(r=null))),$s.clear()}return r||new Error("Unsupported key format")}Ku.exports={isParsedKey:Wu,isSupportedKeyType:Qu,parseDERKey:(n,t)=>va(n,t,"",t),parseKey:qu}});var Ta=lt((Bx,td)=>{"use strict";var{Socket:Gu}=require("net"),{Duplex:ju}=require("stream"),{resolve:Ag}=require("path"),{readFile:Vu}=require("fs"),{execFile:Eg,spawn:yg}=require("child_process"),{isParsedKey:zu,parseKey:Di}=nr(),{makeBufferParser:_g,readUInt32BE:Pa,writeUInt32BE:sn,writeUInt32LE:Yu}=bn();function Mi(n){let t=!1;return(...e)=>{t||(t=!0,n(...e))}}function Sg(n,t){let e=Buffer.allocUnsafe(n.length+t.length);return n.copy(e,0),t.copy(e,n.length),e}function Na(){}var bg=Buffer.alloc(0),It=_g(),Ui=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"))}},Vr=class extends Ui{constructor(t){super(),this.socketPath=t}getStream(t){t=Mi(t);let e=new Gu;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=Mi(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 Ba(!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=Mi(s),this.getStream((i,o)=>{function a(l){if(o)try{o.destroy()}catch{}l||(l=new Error("Failed to sign data with agent")),s(l)}if(i)return a(i);let c=new Ba(!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,(l,f)=>{if(l)return a(l);try{o.destroy()}catch{}s(null,f)})})}},Xu=(()=>{let o=Ag(__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(f){f.buffer=null,f.proc&&(f.proc.kill(),f.proc=void 0)}class l extends ju{constructor(){super(),this.proc=void 0,this.buffer=null}_read(u){}_write(u,h,p){if(this.buffer===null)this.buffer=u;else{let x=Buffer.allocUnsafe(this.buffer.length+u.length);this.buffer.copy(x,0),u.copy(x,this.buffer.length),this.buffer=x}if(this.buffer.length<4)return p();let A=Pa(this.buffer,0);if(this.buffer.length-4<A)return p();if(u=this.buffer.slice(0,4+A),this.buffer.length>4+A)return p(new Error("Unexpected multiple agent requests"));this.buffer=null;let y,b=this.proc=yg(o,[u.length]);b.stdout.on("data",x=>{this.push(x)}),b.on("error",x=>{y=x,p(y)}),b.on("close",x=>{if(this.proc=void 0,!y){if(y=a[x])return p(y);p()}}),b.stdin.end(u)}_final(u){c(this),u()}_destroy(u,h){c(this),h()}}return class extends Vr{getStream(u){u(null,new l)}}})(),Ju=(()=>{let n=/^!<socket >(\d+) s ([A-Z0-9]{8}-[A-Z0-9]{8}-[A-Z0-9]{8}-[A-Z0-9]{8})/;return class extends Vr{getStream(e){e=Mi(e);let r=this.socketPath,s=!1;Vu(r,function i(o,a){if(o){if(s)return e(new Error("Invalid cygwin unix socket path"));Eg("cygpath",["-w",r],(Q,N,S)=>{if(Q||N.length===0)return e(new Error("Invalid cygwin unix socket path"));s=!0,r=N.toString().replace(/[\r\n]/g,""),Vu(r,i)});return}let c=n.exec(a.toString("ascii"));if(!c)return e(new Error("Malformed cygwin unix socket file"));let l,f=0,u=!1,h=[],p,A=Buffer.alloc(12),y=parseInt(c[1],10),b=c[2].replace(/-/g,""),x=Buffer.allocUnsafe(16);for(let Q=0,N=0;N<32;++Q,N+=2)x[Q]=parseInt(b.substring(N,N+2),16);for(let Q=0;Q<16;Q+=4)Yu(x,Pa(x,Q),Q);M();function B(){f=0,l="secret",p.write(x)}function H(Q){if(f+=Q.length,l==="secret"){f===16&&(f=0,l="creds",p.write(A));return}if(l==="creds"&&(u||h.push(Q),f===12)){if(p.removeListener("connect",B),p.removeListener("data",H),p.removeListener("error",C),p.removeListener("end",C),p.removeListener("close",C),u)return e(null,p);u=!0,A=Buffer.concat(h),Yu(A,process.pid,0),p.on("error",()=>{}),p.destroy(),M()}}function C(){e(new Error("Problem negotiating cygwin unix socket security"))}function M(){p=new Gu,p.on("connect",B),p.on("data",H),p.on("error",C),p.on("end",C),p.on("close",C),p.connect(y)}})}}})(),xg=/^[/\\][/\\]\.[/\\]pipe[/\\].+/;function Zu(n){return process.platform==="win32"&&!xg.test(n)?n==="pageant"?new Xu:new Ju(n):new Vr(n)}var Ba=(()=>{function l(S){let w;for(;S[B].length;){let v=S[B][0][u];if(v===void 0)break;S[B].shift(),w=S.push(v)}return w}let f=Symbol("Inbound Request Type"),u=Symbol("Inbound Request Response"),h=Symbol("Inbound Request Context");class p{constructor(w,v){this[f]=w,this[u]=void 0,this[h]=v}hasResponded(){return this[u]!==void 0}getType(){return this[f]}getContext(){return this[h]}}function A(S,w,v){return w[u]=v,l(S)}function y(S){if(S[C]=null,S[H]===0){let w=S[B];if(w&&w.length){S[B]=[];for(let v of w)v.cb(new Error("No reply from server"))}}try{S.end()}catch{}setImmediate(()=>{S[N]||S.emit("end"),S[Q]||S.emit("close")})}function b(){this[Q]=!0}function x(){this[N]=!0}let B=Symbol("Requests"),H=Symbol("Agent Protocol Role"),C=Symbol("Agent Protocol Buffer"),M=Symbol("Agent Protocol Current Message Length"),Q=Symbol("Agent Protocol Closed"),N=Symbol("Agent Protocol Ended");return class extends ju{constructor(w){super({autoDestroy:!0,emitClose:!1}),this[H]=w?0:1,this[B]=[],this[C]=null,this[M]=-1,this.once("end",x),this.once("close",b)}_read(w){}_write(w,v,k){this[C]===null?this[C]=w:this[C]=Sg(this[C],w);let P=this[C],ne=P.length,Y=0;for(;Y<ne&&!(ne<5||(this[M]===-1&&(this[M]=Pa(P,Y)),ne<4+this[M]));){let G=P[Y+=4];if(++Y,this[H]===0){if(this[B].length===0)return k(new Error("Received unexpected message from server"));let te=this[B].shift();switch(G){case 5:te.cb(new Error("Agent responded with failure"));break;case 12:{if(te.type!==11)return k(new Error("Agent responded with wrong message type"));It.init(P,Y);let le=It.readUInt32BE();if(le===void 0)return It.clear(),k(new Error("Malformed agent response"));let U=[];for(let R=0;R<le;++R){let O=It.readString();if(O===void 0)return It.clear(),k(new Error("Malformed agent response"));let K=It.readString(!0);if(K===void 0)return It.clear(),k(new Error("Malformed agent response"));O=Di(O),!(O instanceof Error)&&(O.comment=O.comment||K,U.push(O))}Y=It.pos(),It.clear(),te.cb(null,U);break}case 14:{if(te.type!==13)return k(new Error("Agent responded with wrong message type"));It.init(P,Y);let le=It.readString();if(Y=It.pos(),It.clear(),le===void 0)return k(new Error("Malformed agent response"));if(It.init(le,0),It.readString(!0),le=It.readString(),It.clear(),le===void 0)return k(new Error("Malformed OpenSSH signature format"));te.cb(null,le);break}default:return k(new Error("Agent responded with unsupported message type"))}}else switch(G){case 11:{let te=new p(G);this[B].push(te),this.emit("identities",te);break}case 13:{It.init(P,Y);let te=It.readString(),le=It.readString(),U=It.readUInt32BE();if(Y=It.pos(),It.clear(),U===void 0){let ee=new p(G);return this[B].push(ee),this.failureReply(ee)}if(te=Di(te),te instanceof Error){let ee=new p(G);return this[B].push(ee),this.failureReply(ee)}let R={hash:void 0},O;te.type==="ssh-rsa"&&(U&2?(O="rsa-sha2-256",R.hash="sha256"):U&4&&(O="rsa-sha2-512",R.hash="sha512")),O===void 0&&(O=te.type);let K=new p(G,O);this[B].push(K),this.emit("sign",K,te,le,R);break}default:{let te=new p(G);this[B].push(te),this.failureReply(te)}}if(this[M]=-1,Y===ne){this[C]=null;break}else this[C]=P=P.slice(Y),ne=P.length,Y=0}k()}_destroy(w,v){y(this),v()}_final(w){y(this),w()}sign(w,v,k,P){if(this[H]!==0)throw new Error("Client-only method called with server role");typeof k=="function"?(P=k,k=void 0):(typeof k!="object"||k===null)&&(k=void 0);let ne=0;if(w=Di(w),w instanceof Error)throw new Error("Invalid public key argument");if(w.type==="ssh-rsa"&&k)switch(k.hash){case"sha256":ne=2;break;case"sha512":ne=4;break}w=w.getPublicSSH();let Y=13,G=w.length,te=v.length,le=0,U=Buffer.allocUnsafe(9+G+4+te+4);return sn(U,U.length-4,le),U[le+=4]=Y,sn(U,G,++le),w.copy(U,le+=4),sn(U,te,le+=G),v.copy(U,le+=4),sn(U,ne,le+=te),typeof P!="function"&&(P=Na),this[B].push({type:Y,cb:P}),this.push(U)}getIdentities(w){if(this[H]!==0)throw new Error("Client-only method called with server role");let v=11,k=0,P=Buffer.allocUnsafe(5);return sn(P,P.length-4,k),P[k+=4]=v,typeof w!="function"&&(w=Na),this[B].push({type:v,cb:w}),this.push(P)}failureReply(w){if(this[H]!==1)throw new Error("Server-only method called with client role");if(!(w instanceof p))throw new Error("Wrong request argument");if(w.hasResponded())return!0;let v=0,k=Buffer.allocUnsafe(5);return sn(k,k.length-4,v),k[v+=4]=5,A(this,w,k)}getIdentitiesReply(w,v){if(this[H]!==1)throw new Error("Server-only method called with client role");if(!(w instanceof p))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(v))throw new Error("Keys argument must be an array");let k=4,P=[];for(let G=0;G<v.length;++G){let te=v[G];if(typeof te!="object"||te===null)throw new Error(`Invalid key entry: ${te}`);let le,U;if(zu(te))le=te;else if(zu(te.pubKey))le=te.pubKey;else if(typeof te.pubKey!="object"||te.pubKey===null||({pubKey:le,comment:U}=te.pubKey,le=Di(le),le instanceof Error))continue;U=le.comment||U,le=le.getPublicSSH(),k+=4+le.length,U&&typeof U=="string"?U=Buffer.from(U):Buffer.isBuffer(U)||(U=bg),k+=4+U.length,P.push({pubKey:le,comment:U})}let ne=0,Y=Buffer.allocUnsafe(5+k);sn(Y,Y.length-4,ne),Y[ne+=4]=12,sn(Y,P.length,++ne),ne+=4;for(let G=0;G<P.length;++G){let{pubKey:te,comment:le}=P[G];sn(Y,te.length,ne),te.copy(Y,ne+=4),sn(Y,le.length,ne+=te.length),ne+=4,le.length&&(le.copy(Y,ne),ne+=le.length)}return A(this,w,Y)}signReply(w,v){if(this[H]!==1)throw new Error("Server-only method called with client role");if(!(w instanceof p))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(v))throw new Error("Signature argument must be a Buffer");if(v.length===0)throw new Error("Signature argument must be non-empty");let k=0,P=w.getContext(),ne=Buffer.byteLength(P),Y=Buffer.allocUnsafe(13+ne+4+v.length);return sn(Y,Y.length-4,k),Y[k+=4]=14,sn(Y,4+ne+4+v.length,++k),sn(Y,ne,k+=4),Y.utf8Write(P,k+=4,ne),sn(Y,v.length,k+=ne),v.copy(Y,k+=4),A(this,w,Y)}}})(),ka=Symbol("Agent"),In=Symbol("Agent Keys"),qn=Symbol("Agent Keys Index"),Kr=Symbol("Agent Init Callbacks"),Ra=class{constructor(t){if(typeof t=="string")t=Zu(t);else if(!ed(t))throw new Error("Invalid agent argument");this[ka]=t,this[In]=null,this[qn]=-1,this[Kr]=null}init(t){if(typeof t!="function"&&(t=Na),this[In]===null)if(this[Kr]===null){this[Kr]=[t];let e=(...r)=>{process.nextTick(()=>{let s=this[Kr];this[Kr]=null;for(let i of s)i(...r)})};this[ka].getIdentities(Mi((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=Di(o),!(o instanceof Error)&&i.push(o);this[In]=i,this[qn]=-1,e()}))}else this[Kr].push(t);else process.nextTick(t)}nextKey(){return this[In]===null||++this[qn]>=this[In].length?!1:this[In][this[qn]]}currentKey(){return this[In]===null||this[qn]>=this[In].length?null:this[In][this[qn]]}pos(){return this[In]===null||this[qn]>=this[In].length?-1:this[qn]}reset(){this[qn]=-1}sign(...t){this[ka].sign(...t)}};function ed(n){return n instanceof Ui}td.exports={AgentContext:Ra,AgentProtocol:Ba,BaseAgent:Ui,createAgent:Zu,CygwinAgent:Ju,isAgent:ed,OpenSSHAgent:Vr,PageantAgent:Xu}});var $a=lt((Rx,nd)=>{"use strict";var{kMaxLength:wg}=require("buffer"),{createInflate:Ig,constants:{DEFLATE:Cg,INFLATE:vg,Z_DEFAULT_CHUNK:kg,Z_DEFAULT_COMPRESSION:Ng,Z_DEFAULT_MEMLEVEL:Bg,Z_DEFAULT_STRATEGY:Rg,Z_DEFAULT_WINDOWBITS:Pg,Z_PARTIAL_FLUSH:Tg}}=require("zlib"),Og=Ig()._handle.constructor;function Lg(){throw new Error("Should not get here")}function Dg(n,t,e){let r=this._owner,s=new Error(n);s.errno=t,s.code=e,r._err=s}function Ua(n){n._handle&&(n._handle.close(),n._handle=null)}var Ks=class{constructor(t){let e=Pg,r=Ng,s=Bg,i=Rg,o=void 0;this._err=void 0,this._writeState=new Uint32Array(2),this._chunkSize=kg,this._maxOutputLength=wg,this._outBuffer=Buffer.allocUnsafe(this._chunkSize),this._outOffset=0,this._handle=new Og(t),this._handle._owner=this,this._handle.onerror=Dg,this._handle.init(e,r,s,i,this._writeState,Lg,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,l,f=0,u=this._writeState,h=this._outBuffer,p=this._outOffset,A=this._chunkSize;for(;;){if(r.writeSync(Tg,t,o,s,h,p,i),this._err)throw this._err;a=u[0],c=u[1];let b=s-c,x=i-a;if(x>0){let B=p===0&&x===h.length?h:h.slice(p,p+x);if(p+=x,l?l.push===void 0?l=[l,B]:l.push(B):l=B,f+=B.byteLength,f>this._maxOutputLength)throw Ua(this),new Error(`Output length exceeded maximum of ${this._maxOutputLength}`)}else if(x!==0)throw new Error("have should not go down");if((a===0||p>=A)&&(i=A,p=0,h=Buffer.allocUnsafe(A)),a===0)o+=b,s=c;else break}if(this._outBuffer=h,this._outOffset=p,f===0&&(l=Buffer.alloc(0)),e)return l.totalLen=f,l;if(l.push===void 0)return l;let y=Buffer.allocUnsafe(f);for(let b=0,x=0;b<l.length;++b){let B=l[b];y.set(B,x),x+=B.length}return y}},Oa=class{constructor(t){this.allocStart=0,this.allocStartKEX=0,this._protocol=t,this._zlib=new Ks(Cg)}cleanup(){this._zlib&&Ua(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}},La=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}},Da=class{constructor(){this._zlib=new Ks(vg)}cleanup(){this._zlib&&Ua(this._zlib)}read(t){return this._zlib.writeSync(t,!1)}},Ma=class{cleanup(){}read(t){return t}};nd.exports={PacketReader:Ma,PacketWriter:La,ZlibPacketReader:Da,ZlibPacketWriter:Oa}});var ad=lt((Px,od)=>{"use strict";var{bufferSlice:Fa,bufferParser:D,doFatalError:Et,sigSSHToASN1:rd,writeUInt32BE:id}=bn(),{CHANNEL_OPEN_FAILURE:Mg,COMPAT:Ug,MESSAGE:St,TERMINAL_MODE:sd}=Qn(),{parseKey:$g}=nr(),Fg=Array.from(Object.entries(sd)).reduce((n,[t,e])=>({...n,[t]:e}),{});od.exports={[St.DISCONNECT]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE(),r=D.readString(!0),s=D.readString();if(D.clear(),s===void 0)return Et(n,"Inbound: Malformed DISCONNECT packet");n._debug&&n._debug(`Inbound: Received DISCONNECT (${e}, "${r}")`);let i=n._handlers.DISCONNECT;i&&i(n,e,r)},[St.IGNORE]:(n,t)=>{n._debug&&n._debug("Inbound: Received IGNORE")},[St.UNIMPLEMENTED]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE();if(D.clear(),e===void 0)return Et(n,"Inbound: Malformed UNIMPLEMENTED packet");n._debug&&n._debug(`Inbound: Received UNIMPLEMENTED (seqno ${e})`)},[St.DEBUG]:(n,t)=>{D.init(t,1);let e=D.readBool(),r=D.readString(!0),s=D.readString();if(D.clear(),s===void 0)return Et(n,"Inbound: Malformed DEBUG packet");n._debug&&n._debug("Inbound: Received DEBUG");let i=n._handlers.DEBUG;i&&i(n,e,r)},[St.SERVICE_REQUEST]:(n,t)=>{D.init(t,1);let e=D.readString(!0);if(D.clear(),e===void 0)return Et(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)},[St.SERVICE_ACCEPT]:(n,t)=>{D.init(t,1);let e=D.readString(!0);if(D.clear(),e===void 0)return Et(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)},[St.EXT_INFO]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE(),r;if(e!==void 0){r=[];for(let i=0;i<e;++i){let o=D.readString(!0),a=D.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(D.clear(),r===void 0)return Et(n,"Inbound: Malformed EXT_INFO packet");n._debug&&n._debug("Inbound: Received EXT_INFO");let s=n._handlers.EXT_INFO;s&&s(n,r)},[St.USERAUTH_REQUEST]:(n,t)=>{D.init(t,1);let e=D.readString(!0),r=D.readString(!0),s=D.readString(!0),i,o;switch(s){case"none":i=null;break;case"password":{let c=D.readBool();if(c!==void 0&&(i=D.readString(!0),i!==void 0&&c)){let l=D.readString(!0);l!==void 0?i={oldPassword:i,newPassword:l}:i=void 0}break}case"publickey":{let c=D.readBool();if(c!==void 0){let l=D.readString(!0),f=l,u=D.readString(),h;switch(l){case"rsa-sha2-256":f="ssh-rsa",h="sha256";break;case"rsa-sha2-512":f="ssh-rsa",h="sha512";break}if(c){let p=D.pos(),A=D.readString();if(A!==void 0&&(A.length>4+l.length+4&&A.utf8Slice(4,4+l.length)===l&&(A=Fa(A,4+l.length+4)),A=rd(A,f),A)){let y=n._kex.sessionID,b=Buffer.allocUnsafe(4+y.length+p);id(b,y.length,0),b.set(y,4),b.set(new Uint8Array(t.buffer,t.byteOffset,p),4+y.length),i={keyAlgo:f,key:u,signature:A,blob:b,hashAlgo:h}}}else i={keyAlgo:f,key:u,hashAlgo:h},o="publickey -- check"}break}case"hostbased":{let c=D.readString(!0),l=c,f=D.readString(),u=D.readString(!0),h=D.readString(!0),p;switch(c){case"rsa-sha2-256":l="ssh-rsa",p="sha256";break;case"rsa-sha2-512":l="ssh-rsa",p="sha512";break}let A=D.pos(),y=D.readString();if(y!==void 0&&(y.length>4+c.length+4&&y.utf8Slice(4,4+c.length)===c&&(y=Fa(y,4+c.length+4)),y=rd(y,l),y!==void 0)){let b=n._kex.sessionID,x=Buffer.allocUnsafe(4+b.length+A);id(x,b.length,0),x.set(b,4),x.set(new Uint8Array(t.buffer,t.byteOffset,A),4+b.length),i={keyAlgo:l,key:f,signature:y,blob:x,localHostname:u,localUsername:h,hashAlgo:p}}break}case"keyboard-interactive":D.skipString(),i=D.readList();break;default:s!==void 0&&(i=D.readRaw())}if(D.clear(),i===void 0)return Et(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)},[St.USERAUTH_FAILURE]:(n,t)=>{D.init(t,1);let e=D.readList(),r=D.readBool();if(D.clear(),r===void 0)return Et(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)},[St.USERAUTH_SUCCESS]:(n,t)=>{n._debug&&n._debug("Inbound: Received USERAUTH_SUCCESS"),n._authsQueue.shift();let e=n._handlers.USERAUTH_SUCCESS;e&&e(n)},[St.USERAUTH_BANNER]:(n,t)=>{D.init(t,1);let e=D.readString(!0),r=D.readString();if(D.clear(),r===void 0)return Et(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":{D.init(t,1);let e=D.readString(!0),r=D.readString();if(D.clear(),r===void 0)return Et(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":{D.init(t,1);let e=D.readString(!0),r=D.readString();if(D.clear(),r===void 0)return Et(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":{D.init(t,1);let e=D.readString(!0),r=D.readString(!0);D.readString();let s=D.readUInt32BE(),i;if(s!==void 0){i=new Array(s);let a;for(a=0;a<s;++a){let c=D.readString(!0),l=D.readBool();if(l===void 0)break;i[a]={prompt:c,echo:l}}a!==s&&(i=void 0)}if(D.clear(),i===void 0)return Et(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 Et(n,"Inbound: Received unexpected payload type 61");D.init(t,1);let e=D.readUInt32BE(),r;if(e!==void 0){r=new Array(e);let i;for(i=0;i<e;++i){let o=D.readString(!0);if(o===void 0)break;r[i]=o}i!==e&&(r=void 0)}if(D.clear(),r===void 0)return Et(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)},[St.GLOBAL_REQUEST]:(n,t)=>{D.init(t,1);let e=D.readString(!0),r=D.readBool(),s;if(r!==void 0)switch(e){case"tcpip-forward":case"cancel-tcpip-forward":{let o=D.readString(!0),a=D.readUInt32BE();a!==void 0&&(s={bindAddr:o,bindPort:a});break}case"streamlocal-forward@openssh.com":case"cancel-streamlocal-forward@openssh.com":{let o=D.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=[];D.avail()>0;){let o=D.readString();if(o===void 0){s=void 0;break}let a=$g(o);a instanceof Error||s.push(a)}break}default:s=D.readRaw()}if(D.clear(),s===void 0)return Et(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()},[St.REQUEST_SUCCESS]:(n,t)=>{let e=t.length>1?Fa(t,1):null;n._debug&&n._debug("Inbound: REQUEST_SUCCESS");let r=n._handlers.REQUEST_SUCCESS;r&&r(n,e)},[St.REQUEST_FAILURE]:(n,t)=>{n._debug&&n._debug("Inbound: Received REQUEST_FAILURE");let e=n._handlers.REQUEST_FAILURE;e&&e(n)},[St.CHANNEL_OPEN]:(n,t)=>{D.init(t,1);let e=D.readString(!0),r=D.readUInt32BE(),s=D.readUInt32BE(),i=D.readUInt32BE(),o;switch(e){case"forwarded-tcpip":case"direct-tcpip":{let c=D.readString(!0),l=D.readUInt32BE(),f=D.readString(!0),u=D.readUInt32BE();u!==void 0&&(o={type:e,sender:r,window:s,packetSize:i,data:{destIP:c,destPort:l,srcIP:f,srcPort:u}});break}case"forwarded-streamlocal@openssh.com":case"direct-streamlocal@openssh.com":{let c=D.readString(!0);c!==void 0&&(o={type:e,sender:r,window:s,packetSize:i,data:{socketPath:c}});break}case"x11":{let c=D.readString(!0),l=D.readUInt32BE();l!==void 0&&(o={type:e,sender:r,window:s,packetSize:i,data:{srcIP:c,srcPort:l}});break}default:o={type:e,sender:r,window:s,packetSize:i,data:{}}}if(D.clear(),o===void 0)return Et(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,Mg.ADMINISTRATIVELY_PROHIBITED,"","")},[St.CHANNEL_OPEN_CONFIRMATION]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE(),r=D.readUInt32BE(),s=D.readUInt32BE(),i=D.readUInt32BE(),o=D.avail()?D.readRaw():void 0;if(D.clear(),i===void 0)return Et(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})},[St.CHANNEL_OPEN_FAILURE]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE(),r=D.readUInt32BE(),s=D.readString(!0),i=D.readString();if(D.clear(),i===void 0)return Et(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)},[St.CHANNEL_WINDOW_ADJUST]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE(),r=D.readUInt32BE();if(D.clear(),r===void 0)return Et(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)},[St.CHANNEL_DATA]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE(),r=D.readString();if(D.clear(),r===void 0)return Et(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)},[St.CHANNEL_EXTENDED_DATA]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE(),r=D.readUInt32BE(),s=D.readString();if(D.clear(),s===void 0)return Et(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)},[St.CHANNEL_EOF]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE();if(D.clear(),e===void 0)return Et(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)},[St.CHANNEL_CLOSE]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE();if(D.clear(),e===void 0)return Et(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)},[St.CHANNEL_REQUEST]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE(),r=D.readString(!0),s=D.readBool(),i;if(s!==void 0)switch(r){case"exit-status":i=D.readUInt32BE(),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${i})`);break;case"exit-signal":{let a,c;if(n._compatFlags&Ug.OLD_EXIT){let f=D.readUInt32BE();switch(f){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:f!==void 0&&(a=`UNKNOWN (${f})`)}c=!1}else a=D.readString(!0),c=D.readBool(),c===void 0&&(a=void 0);let l=D.readString(!0);D.skipString()!==void 0&&(i={signal:a,coreDumped:c,errorMessage:l}),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${a})`);break}case"pty-req":{let a=D.readString(!0),c=D.readUInt32BE(),l=D.readUInt32BE(),f=D.readUInt32BE(),u=D.readUInt32BE(),h=D.readString();if(h!==void 0){D.init(h,1);let p={};for(;D.avail();){let A=D.readByte();if(A===sd.TTY_OP_END)break;let y=Fg[A],b=D.readUInt32BE();if(A===void 0||y===void 0||b===void 0){p=void 0;break}p[y]=b}p!==void 0&&(i={term:a,cols:c,rows:l,width:f,height:u,modes:p})}n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break}case"window-change":{let a=D.readUInt32BE(),c=D.readUInt32BE(),l=D.readUInt32BE(),f=D.readUInt32BE();f!==void 0&&(i={cols:a,rows:c,width:l,height:f}),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break}case"x11-req":{let a=D.readBool(),c=D.readString(!0),l=D.readString(),f=D.readUInt32BE();f!==void 0&&(i={single:a,protocol:c,cookie:l,screen:f}),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break}case"env":{let a=D.readString(!0),c=D.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=D.readString(!0),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${i})`);break;case"subsystem":i=D.readString(!0),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${i})`);break;case"signal":i=D.readString(!0),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${i})`);break;case"xon-xoff":i=D.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=D.avail()?D.readRaw():null,n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`)}if(D.clear(),i===void 0)return Et(n,"Inbound: Malformed CHANNEL_REQUEST packet");let o=n._handlers.CHANNEL_REQUEST;o&&o(n,e,r,s,i)},[St.CHANNEL_SUCCESS]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE();if(D.clear(),e===void 0)return Et(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)},[St.CHANNEL_FAILURE]:(n,t)=>{D.init(t,1);let e=D.readUInt32BE();if(D.clear(),e===void 0)return Et(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 Vs=lt((Tx,cd)=>{"use strict";var Ha=new Array(256);[zs().HANDLERS,ad()].forEach(n=>{for(let[t,e]of Object.entries(n))t=+t,isFinite(t)&&t>=0&&t<Ha.length&&(Ha[t]=e)});cd.exports=Ha});var zs=lt((Lx,Ed)=>{"use strict";var{createDiffieHellman:Hg,createDiffieHellmanGroup:Qg,createECDH:Wg,createHash:Wa,createPublicKey:qg,diffieHellman:Kg,generateKeyPairSync:Vg,randomFillSync:zg}=require("crypto"),{Ber:ld}=Si(),{COMPAT:qa,curve25519Supported:Yg,DEFAULT_KEX:fd,DEFAULT_SERVER_HOST_KEY:ud,DEFAULT_CIPHER:Ys,DEFAULT_MAC:Gs,DEFAULT_COMPRESSION:js,DISCONNECT_REASON:Ge,MESSAGE:mt}=Qn(),{CIPHER_INFO:Gr,createCipher:Gg,createDecipher:jg,MAC_INFO:dd}=Zn(),{parseDERKey:Xg}=nr(),{bufferFill:Jg,bufferParser:Ye,convertSignature:Zg,doFatalError:je,FastBuffer:e0,sigSSHToASN1:t0,writeUInt32BE:Qt}=bn(),{PacketReader:hd,PacketWriter:pd,ZlibPacketReader:Xs,ZlibPacketWriter:Js}=$a(),zr,n0=2048,r0=8192,i0=Buffer.alloc(0);function md(n){let t;if(n._compatFlags&qa.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),Qt(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]=mt.KEXINIT,zg(t,1,16),Jg(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 gd(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(Ye.init(t,17),(e.kex=Ye.readList())===void 0||(e.serverHostKey=Ye.readList())===void 0||(e.cs.cipher=Ye.readList())===void 0||(e.sc.cipher=Ye.readList())===void 0||(e.cs.mac=Ye.readList())===void 0||(e.sc.mac=Ye.readList())===void 0||(e.cs.compress=Ye.readList())===void 0||(e.sc.compress=Ye.readList())===void 0||(e.cs.lang=Ye.readList())===void 0||(e.sc.lang=Ye.readList())===void 0)return Ye.clear(),je(n,"Received malformed KEXINIT","handshake",Ge.KEY_EXCHANGE_FAILED);let r=Ye.pos(),s=r<t.length&&t[r]===1;Ye.clear();let i=n._offer,o=e,a=i.lists.kex.array;if(n._compatFlags&qa.BAD_DHGEX){let C=!1;for(let M=0;M<a.length;++M)a[M].indexOf("group-exchange")!==-1&&(C||(C=!0,a=a.slice()),a.splice(M--,1))}let c,l,f,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?(l=a,c=o.kex,h=c.indexOf("ext-info-c")!==-1):(l=o.kex,c=a,h=l.indexOf("ext-info-s")!==-1),n._strictMode===void 0&&(n._server?n._strictMode=c.indexOf("kex-strict-c-v00@openssh.com")!==-1:n._strictMode=l.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"),je(n,"Handshake failed: KEXINIT not first packet in strict KEX mode","handshake",Ge.KEY_EXCHANGE_FAILED);for(f=0;f<c.length&&l.indexOf(c[f])===-1;++f);if(f===c.length)return u&&u("Handshake: no matching key exchange algorithm"),je(n,"Handshake failed: no matching key exchange algorithm","handshake",Ge.KEY_EXCHANGE_FAILED);e.kex=c[f],u&&u(`Handshake: KEX algorithm: ${c[f]}`),s&&(!o.kex.length||c[f]!==o.kex[0])&&(n._skipNextInboundPacket=!0);let p=i.lists.serverHostKey.array;for(u&&u(`Handshake: (local) Host key format: ${p}`),u&&u(`Handshake: (remote) Host key format: ${o.serverHostKey}`),n._server?(l=p,c=o.serverHostKey):(l=o.serverHostKey,c=p),f=0;f<c.length&&l.indexOf(c[f])===-1;++f);if(f===c.length)return u&&u("Handshake: No matching host key format"),je(n,"Handshake failed: no matching host key format","handshake",Ge.KEY_EXCHANGE_FAILED);e.serverHostKey=c[f],u&&u(`Handshake: Host key format: ${c[f]}`);let A=i.lists.cs.cipher.array;for(u&&u(`Handshake: (local) C->S cipher: ${A}`),u&&u(`Handshake: (remote) C->S cipher: ${o.cs.cipher}`),n._server?(l=A,c=o.cs.cipher):(l=o.cs.cipher,c=A),f=0;f<c.length&&l.indexOf(c[f])===-1;++f);if(f===c.length)return u&&u("Handshake: No matching C->S cipher"),je(n,"Handshake failed: no matching C->S cipher","handshake",Ge.KEY_EXCHANGE_FAILED);e.cs.cipher=c[f],u&&u(`Handshake: C->S Cipher: ${c[f]}`);let y=i.lists.sc.cipher.array;for(u&&u(`Handshake: (local) S->C cipher: ${y}`),u&&u(`Handshake: (remote) S->C cipher: ${o.sc.cipher}`),n._server?(l=y,c=o.sc.cipher):(l=o.sc.cipher,c=y),f=0;f<c.length&&l.indexOf(c[f])===-1;++f);if(f===c.length)return u&&u("Handshake: No matching S->C cipher"),je(n,"Handshake failed: no matching S->C cipher","handshake",Ge.KEY_EXCHANGE_FAILED);e.sc.cipher=c[f],u&&u(`Handshake: S->C cipher: ${c[f]}`);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}`),Gr[e.cs.cipher].authLen>0)e.cs.mac="",u&&u("Handshake: C->S MAC: <implicit>");else{for(n._server?(l=b,c=o.cs.mac):(l=o.cs.mac,c=b),f=0;f<c.length&&l.indexOf(c[f])===-1;++f);if(f===c.length)return u&&u("Handshake: No matching C->S MAC"),je(n,"Handshake failed: no matching C->S MAC","handshake",Ge.KEY_EXCHANGE_FAILED);e.cs.mac=c[f],u&&u(`Handshake: C->S MAC: ${c[f]}`)}let x=i.lists.sc.mac.array;if(u&&u(`Handshake: (local) S->C MAC: ${x}`),u&&u(`Handshake: (remote) S->C MAC: ${o.sc.mac}`),Gr[e.sc.cipher].authLen>0)e.sc.mac="",u&&u("Handshake: S->C MAC: <implicit>");else{for(n._server?(l=x,c=o.sc.mac):(l=o.sc.mac,c=x),f=0;f<c.length&&l.indexOf(c[f])===-1;++f);if(f===c.length)return u&&u("Handshake: No matching S->C MAC"),je(n,"Handshake failed: no matching S->C MAC","handshake",Ge.KEY_EXCHANGE_FAILED);e.sc.mac=c[f],u&&u(`Handshake: S->C MAC: ${c[f]}`)}let B=i.lists.cs.compress.array;for(u&&u(`Handshake: (local) C->S compression: ${B}`),u&&u(`Handshake: (remote) C->S compression: ${o.cs.compress}`),n._server?(l=B,c=o.cs.compress):(l=o.cs.compress,c=B),f=0;f<c.length&&l.indexOf(c[f])===-1;++f);if(f===c.length)return u&&u("Handshake: No matching C->S compression"),je(n,"Handshake failed: no matching C->S compression","handshake",Ge.KEY_EXCHANGE_FAILED);e.cs.compress=c[f],u&&u(`Handshake: C->S compression: ${c[f]}`);let H=i.lists.sc.compress.array;for(u&&u(`Handshake: (local) S->C compression: ${H}`),u&&u(`Handshake: (remote) S->C compression: ${o.sc.compress}`),n._server?(l=H,c=o.sc.compress):(l=o.sc.compress,c=H),f=0;f<c.length&&l.indexOf(c[f])===-1;++f);if(f===c.length)return u&&u("Handshake: No matching S->C compression"),je(n,"Handshake failed: no matching S->C compression","handshake",Ge.KEY_EXCHANGE_FAILED);e.sc.compress=c[f],u&&u(`Handshake: S->C compression: ${c[f]}`),e.cs.lang="",e.sc.lang="",n._kex&&(n._kexinit||md(n),n._decipher._onPayload=Ad.bind(n,{firstPacket:!1})),n._kex=s0(e,n,t),n._kex.remoteExtInfoEnabled=h,n._kex.start()}var s0=(()=>{function n(o){let a=0,c=o.length;for(;o[a]===0;)++a,--c;let l;return o[a]&128?(l=Buffer.allocUnsafe(1+c),l[0]=0,o.copy(l,1,a),o=l):c!==o.length&&(l=Buffer.allocUnsafe(c),o.copy(l,0,a),o=l),o}class t{constructor(a,c,l){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=l,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,l=this.negotiated,f=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",je(this._protocol,u,Ge.KEY_EXCHANGE_FAILED);let h=Wa(this.hashName);Pn(h,c?this._remoteIdentRaw:this._identRaw),Pn(h,c?this._identRaw:this._remoteIdentRaw),Pn(h,c?this._remoteKexinit:this._kexinit),Pn(h,c?this._kexinit:this._remoteKexinit);let p=c?this._hostKey.getPublicSSH():this._hostKey;if(Pn(h,p),this.type==="groupex"){let H=this.getDHParams(),C=Buffer.allocUnsafe(4);Qt(C,this._minBits,0),h.update(C),Qt(C,this._prefBits,0),h.update(C),Qt(C,this._maxBits,0),h.update(C),Pn(h,H.prime),Pn(h,H.generator)}Pn(h,c?f:this.getPublicKey());let A=c?this.getPublicKey():f;Pn(h,A),Pn(h,u);let y=h.digest();if(c){let H;switch(this.negotiated.serverHostKey){case"rsa-sha2-256":H="sha256";break;case"rsa-sha2-512":H="sha512";break}this._protocol._debug&&this._protocol._debug("Generating signature ...");let C=this._hostKey.sign(y,H);if(C instanceof Error)return je(this._protocol,`Handshake failed: signature generation failed for ${this._hostKey.type} host key: ${C.message}`,"handshake",Ge.KEY_EXCHANGE_FAILED);if(C=Zg(C,this._hostKey.type),C===!1)return je(this._protocol,`Handshake failed: signature conversion failed for ${this._hostKey.type} host key`,"handshake",Ge.KEY_EXCHANGE_FAILED);let M=this.negotiated.serverHostKey,Q=Buffer.byteLength(M),N=4+Q+4+C.length,S=this._protocol._packetRW.write.allocStartKEX,w=this._protocol._packetRW.write.alloc(5+p.length+4+A.length+4+N,!0);if(w[S]=mt.KEXDH_REPLY,Qt(w,p.length,++S),w.set(p,S+=4),Qt(w,A.length,S+=p.length),w.set(A,S+=4),Qt(w,N,S+=A.length),Qt(w,Q,S+=4),w.utf8Write(M,S+=4,Q),Qt(w,C.length,S+=Q),w.set(C,S+=4),this._protocol._debug){let v;switch(this.type){case"group":v="KEXDH_REPLY";break;case"groupex":v="KEXDH_GEX_REPLY";break;default:v="KEXECDH_REPLY"}this._protocol._debug(`Outbound: Sending ${v}`)}this._protocol._cipher.encrypt(this._protocol._packetRW.write.finalize(w,!0))}else{Ye.init(this._sig,0);let H=Ye.readString(!0);if(!H)return je(this._protocol,"Malformed packet while reading signature","handshake",Ge.KEY_EXCHANGE_FAILED);if(H!==l.serverHostKey)return je(this._protocol,`Wrong signature type: ${H}, expected: ${l.serverHostKey}`,"handshake",Ge.KEY_EXCHANGE_FAILED);let C=Ye.readString();if(Ye.clear(),C===void 0)return je(this._protocol,"Malformed packet while reading signature","handshake",Ge.KEY_EXCHANGE_FAILED);if(!(C=t0(C,H)))return je(this._protocol,"Malformed signature","handshake",Ge.KEY_EXCHANGE_FAILED);let M;{Ye.init(this._hostKey,0);let S=Ye.readString(!0),w=this._hostKey.slice(Ye.pos());if(Ye.clear(),M=Xg(w,S),M instanceof Error)return M.level="handshake",je(this._protocol,M,Ge.KEY_EXCHANGE_FAILED)}let Q;switch(this.negotiated.serverHostKey){case"rsa-sha2-256":Q="sha256";break;case"rsa-sha2-512":Q="sha512";break}this._protocol._debug&&this._protocol._debug("Verifying signature ...");let N=M.verify(y,C,Q);if(N!==!0)return N instanceof Error?this._protocol._debug&&this._protocol._debug(`Signature verification failed: ${N.stack}`):this._protocol._debug&&this._protocol._debug("Signature verification failed"),je(this._protocol,"Handshake failed: signature verification failed","handshake",Ge.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Verified signature")}(c||!a)&&Zs(this);let b,x,B=H=>{if(b)return Zs(this),b.outbound.seqno=this._protocol._cipher.outSeqno,this._protocol._cipher.free(),this._protocol._cipher=Gg(b),this._protocol._packetRW.write=x,b=void 0,x=void 0,this._protocol._onHandshakeComplete(l),!1;this.sessionID||(this.sessionID=y);{let te=Buffer.allocUnsafe(4+u.length);Qt(te,u.length,0),te.set(u,4),u=te}let C=Gr[l.cs.cipher],M=Gr[l.sc.cipher],Q=Yr(C.ivLen,this.hashName,u,y,this.sessionID,"A"),N=Yr(M.ivLen,this.hashName,u,y,this.sessionID,"B"),S=Yr(C.keyLen,this.hashName,u,y,this.sessionID,"C"),w=Yr(M.keyLen,this.hashName,u,y,this.sessionID,"D"),v,k;C.authLen||(v=dd[l.cs.mac],k=Yr(v.len,this.hashName,u,y,this.sessionID,"E"));let P,ne;M.authLen||(P=dd[l.sc.mac],ne=Yr(P.len,this.hashName,u,y,this.sessionID,"F"));let Y={inbound:{onPayload:this._protocol._onPayload,seqno:this._protocol._decipher.inSeqno,decipherInfo:c?C:M,decipherIV:c?Q:N,decipherKey:c?S:w,macInfo:c?v:P,macKey:c?k:ne},outbound:{onWrite:this._protocol._onWrite,seqno:this._protocol._cipher.outSeqno,cipherInfo:c?M:C,cipherIV:c?N:Q,cipherKey:c?w:S,macInfo:c?P:v,macKey:c?ne:k}};this._protocol._decipher.free(),b=Y,this._protocol._decipher=jg(Y);let G={read:void 0,write:void 0};switch(l.cs.compress){case"zlib":c?G.read=new Xs:G.write=new Js(this._protocol);break;case"zlib@openssh.com":if(this._protocol._authenticated){c?G.read=new Xs:G.write=new Js(this._protocol);break}default:c?G.read=new hd:G.write=new pd(this._protocol)}switch(l.sc.compress){case"zlib":c?G.write=new Js(this._protocol):G.read=new Xs;break;case"zlib@openssh.com":if(this._protocol._authenticated){c?G.write=new Js(this._protocol):G.read=new Xs;break}default:c?G.write=new pd(this._protocol):G.read=new hd}return this._protocol._packetRW.read.cleanup(),this._protocol._packetRW.write.cleanup(),this._protocol._packetRW.read=G.read,x=G.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,H?!1:B()};if((c||a)&&(this.finish=B),!c)return B(a)}start(){if(!this._protocol._server){if(this._protocol._debug){let f;this.type==="group"?f="KEXDH_INIT":f="KEXECDH_INIT",this._protocol._debug(`Outbound: Sending ${f}`)}let a=this.getPublicKey(),c=this._protocol._packetRW.write.allocStartKEX,l=this._protocol._packetRW.write.alloc(5+a.length,!0);l[c]=mt.KEXDH_INIT,Qt(l,a.length,++c),l.set(a,c+=4),this._protocol._cipher.encrypt(this._protocol._packetRW.write.finalize(l,!0))}}getPublicKey(){this.generateKeys();let a=this._public;if(a)return this.convertPublicKey(a)}convertPublicKey(a){let c,l=0,f=a.length;for(;a[l]===0;)++l,--f;return a[l]&128?(c=Buffer.allocUnsafe(1+f),c[0]=0,a.copy(c,1,l),c):(f!==a.length&&(c=Buffer.allocUnsafe(f),a.copy(c,0,l),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!==mt.KEXDH_INIT)return je(this._protocol,`Received packet ${c} instead of ${mt.KEXDH_INIT}`,"handshake",Ge.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH Init"),Ye.init(a,1);let l=Ye.readString();if(Ye.clear(),l===void 0)return je(this._protocol,"Received malformed KEX*_INIT","handshake",Ge.KEY_EXCHANGE_FAILED);this._dhData=l;let f=this._protocol._hostKeys[this.negotiated.serverHostKey];Array.isArray(f)&&(f=f[0]),this._hostKey=f,this.finish()}else{if(c!==mt.KEXDH_REPLY)return je(this._protocol,`Received packet ${c} instead of ${mt.KEXDH_REPLY}`,"handshake",Ge.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH Reply"),Ye.init(a,1);let l,f,u;if((l=Ye.readString())===void 0||(f=Ye.readString())===void 0||(u=Ye.readString())===void 0)return Ye.clear(),je(this._protocol,"Received malformed KEX*_REPLY","handshake",Ge.KEY_EXCHANGE_FAILED);Ye.clear(),Ye.init(l,0);let h=Ye.readString(!0);if(Ye.clear(),h===void 0)return je(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 je(this._protocol,"Host key does not match negotiated type","handshake",Ge.KEY_EXCHANGE_FAILED)}this._hostKey=l,this._dhData=f,this._sig=u;let p=!1,A;if(this._protocol._hostVerifier===void 0?(A=!0,this._protocol._debug&&this._protocol._debug("Host accepted by default (no verification)")):A=this._protocol._hostVerifier(l,y=>{if(!p){if(p=!0,y===!1)return this._protocol._debug&&this._protocol._debug("Host denied (verification failed)"),je(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():Zs(this)}}),A===void 0){++this._step;return}if(p=!0,A===!1)return this._protocol._debug&&this._protocol._debug("Host denied (verification failed)"),je(this._protocol,"Host denied (verification failed)","handshake",Ge.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Host accepted (verified)"),this._hostVerified=!0,Zs(this)}++this._step;break;case 2:return c!==mt.NEWKEYS?je(this._protocol,`Received packet ${c} instead of ${mt.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 je(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=Vg("x25519"))}getPublicKey(){return this.generateKeys(),this._keys.publicKey.export({type:"spki",format:"der"}).slice(-32)}convertPublicKey(a){let c,l=0,f=a.length;for(;a[l]===0;)++l,--f;return a.length===32||f!==a.length&&(c=Buffer.allocUnsafe(f),a.copy(c,0,l),a=c),a}computeSecret(a){this.generateKeys();try{let c=new ld.Writer;return c.startSequence(),c.startSequence(),c.writeOID("1.3.101.110"),c.endSequence(),c.startSequence(ld.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(Kg({privateKey:this._keys.privateKey,publicKey:qg({key:c.buffer,type:"spki",format:"der"})}))}catch(c){return c}}}class r extends t{constructor(a,c,...l){super(...l),this.type="ecdh",this.curveName=a,this.hashName=c}generateKeys(){this._dh||(this._dh=Wg(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=n0,this._prefBits=o0(this.negotiated),this._protocol._compatFlags&qa.BUG_DHGEX_LARGE&&(this._prefBits=Math.min(this._prefBits,4096)),this._maxBits=r0}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]=mt.KEXDH_GEX_REQUEST,Qt(c,this._minBits,++a),Qt(c,this._prefBits,a+=4),Qt(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=Hg(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!==mt.KEXDH_GEX_REQUEST?je(this._protocol,`Received packet ${c} instead of `+mt.KEXDH_GEX_REQUEST,"handshake",Ge.KEY_EXCHANGE_FAILED):je(this._protocol,"Group exchange not implemented for server","handshake",Ge.KEY_EXCHANGE_FAILED);if(c!==mt.KEXDH_GEX_GROUP)return je(this._protocol,`Received packet ${c} instead of ${mt.KEXDH_GEX_GROUP}`,"handshake",Ge.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH GEX Group"),Ye.init(a,1);let l,f;if((l=Ye.readString())===void 0||(f=Ye.readString())===void 0)return Ye.clear(),je(this._protocol,"Received malformed KEXDH_GEX_GROUP","handshake",Ge.KEY_EXCHANGE_FAILED);Ye.clear(),this.setDHParams(l,f),this.generateKeys();let u=this.getPublicKey();this._protocol._debug&&this._protocol._debug("Outbound: Sending KEXDH_GEX_INIT");let h=this._protocol._packetRW.write.allocStartKEX,p=this._protocol._packetRW.write.alloc(5+u.length,!0);p[h]=mt.KEXDH_GEX_INIT,Qt(p,u.length,++h),p.set(u,h+=4),this._protocol._cipher.encrypt(this._protocol._packetRW.write.finalize(p,!0)),++this._step;break}case 2:if(this._protocol._server)return c!==mt.KEXDH_GEX_INIT?je(this._protocol,`Received packet ${c} instead of ${mt.KEXDH_GEX_INIT}`,"handshake",Ge.KEY_EXCHANGE_FAILED):(this._protocol._debug&&this._protocol._debug("Received DH GEX Init"),je(this._protocol,"Group exchange not implemented for server","handshake",Ge.KEY_EXCHANGE_FAILED));if(c!==mt.KEXDH_GEX_REPLY)return je(this._protocol,`Received packet ${c} instead of ${mt.KEXDH_GEX_REPLY}`,"handshake",Ge.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH GEX Reply"),this._step=1,a[0]=mt.KEXDH_REPLY,this.parse=t.prototype.parse,this.parse(a)}}}class i extends t{constructor(a,c,...l){super(...l),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,l=this._protocol._packetRW.write.alloc(5+a.length,!0);l[c]=mt.KEXDH_INIT,Qt(l,a.length,++c),l.set(a,c+=4),this._protocol._cipher.encrypt(this._protocol._packetRW.write.finalize(l,!0))}}generateKeys(){this._dh||(this._dh=Qg(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(!Yg)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}`)}})(),Qa=(()=>{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,l,f,u;if(typeof a=="string")c=r,l=e[a],f=u=a;else{let p=a[0];c=r[p],u=a[1],l=e[p][u],f=`${p}.${u}`}let h={array:void 0,buffer:void 0};if(Buffer.isBuffer(l))h.array=(""+l).split(","),h.buffer=l,s+=4+l.length;else{if(typeof l=="string"&&(l=l.split(",")),Array.isArray(l))h.array=l,h.buffer=Buffer.from(l.join(","));else throw new TypeError(`Invalid \`${f}\` type: ${typeof l}`);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=Qt(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}}})(),Pn=(()=>{let n=Buffer.allocUnsafe(4);return(t,e)=>{Qt(n,e.length,0),t.update(n),t.update(e)}})();function Yr(n,t,e,r,s,i){let o;if(n){let a=Wa(t).update(e).update(r).update(i).update(s).digest();for(;a.length<n;){let c=Wa(t).update(e).update(r).update(a).digest(),l=Buffer.allocUnsafe(a.length+c.length);l.set(a,0),l.set(c,a.length),a=l}a.length===n?o=a:o=new e0(a.buffer,a.byteOffset,n)}else o=i0;return o}function Ad(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 mt.IGNORE:case mt.UNIMPLEMENTED:case mt.DEBUG:return zr||(zr=Vs()),zr[e](this,t)}switch(e){case mt.DISCONNECT:return zr||(zr=Vs()),zr[e](this,t);case mt.KEXINIT:return n.firstPacket?(n.firstPacket=!1,gd(this,t)):je(this,"Received extra KEXINIT during handshake","handshake",Ge.KEY_EXCHANGE_FAILED);default:if(e<20||e>49)return je(this,`Received unexpected packet type ${e}`,"handshake",Ge.KEY_EXCHANGE_FAILED)}return this._kex.parse(t)}function o0(n){let t=Gr[n.cs.cipher],e=Gr[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 Zs(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]=mt.NEWKEYS,n._protocol._cipher.encrypt(n._protocol._packetRW.write.finalize(e,!0)),n._sentNEWKEYS=!0,n._protocol._strictMode&&(n._protocol._cipher.outSeqno=0)}}Ed.exports={KexInit:Qa,kexinit:md,onKEXPayload:Ad,DEFAULT_KEXINIT_CLIENT:new Qa({kex:fd.concat(["ext-info-c","kex-strict-c-v00@openssh.com"]),serverHostKey:ud,cs:{cipher:Ys,mac:Gs,compress:js,lang:[]},sc:{cipher:Ys,mac:Gs,compress:js,lang:[]}}),DEFAULT_KEXINIT_SERVER:new Qa({kex:fd.concat(["kex-strict-s-v00@openssh.com"]),serverHostKey:ud,cs:{cipher:Ys,mac:Gs,compress:js,lang:[]},sc:{cipher:Ys,mac:Gs,compress:js,lang:[]}}),HANDLERS:{[mt.KEXINIT]:gd}}});var yd=lt((Dx,a0)=>{a0.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 Ya=lt((Mx,Pd)=>{"use strict";var{inspect:Id}=require("util"),{bindingAvailable:c0,NullCipher:l0,NullDecipher:f0}=Zn(),{COMPAT_CHECKS:u0,DISCONNECT_REASON:Cd,eddsaSupported:d0,MESSAGE:we,SIGNALS:_d,TERMINAL_MODE:Va}=Qn(),{DEFAULT_KEXINIT_CLIENT:h0,DEFAULT_KEXINIT_SERVER:p0,KexInit:Sd,kexinit:vd,onKEXPayload:m0}=zs(),{parseKey:bd}=nr(),g0=Vs(),{bufferCopy:eo,bufferFill:A0,bufferSlice:kd,convertSignature:xd,sendPacket:Ie,writeUInt32BE:T}=bn(),{PacketReader:E0,PacketWriter:y0,ZlibPacketReader:Nd,ZlibPacketWriter:Bd}=$a(),_0=yd().version,S0=new Map(Object.values(Cd).map(n=>[n,1])),Rd=Buffer.from(`SSH-2.0-ssh2js${_0}`),b0=Buffer.from(`${Rd}\r
8
- `),x0=8192,w0=1024,wd=Buffer.from([we.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]),I0=Buffer.from([Va.TTY_OP_END]);function Ka(){}var za=class{constructor(t){let e=t.onWrite;if(typeof e!="function")throw new Error("Missing onWrite function");this._onWrite=p=>{e(p)};let r=t.onError;if(typeof r!="function")throw new Error("Missing onError function");this._onError=p=>{r(p)};let s=t.debug;this._debug=typeof s=="function"?p=>{s(p)}:void 0;let i=t.onHeader;this._onHeader=typeof i=="function"?(...p)=>{i(...p)}:Ka;let o=t.onPacket;this._onPacket=typeof o=="function"?()=>{o()}:Ka;let a=t.onHandshakeComplete;typeof a!="function"&&(a=Ka);let c;this._onHandshakeComplete=(...p)=>{this._debug&&this._debug("Handshake completed"),c===void 0?c=!0:c=!1;let A=this._queue;if(A){this._queue=void 0,this._debug&&this._debug(`Draining outbound queue (${A.length}) ...`);for(let y=0;y<A.length;++y){let b=A[y],x=this._packetRW.write.finalize(b);if(x===b){let B=this._cipher.allocPacket(b.length);B.set(b,5),x=B}Ie(this,x)}this._debug&&this._debug("... finished draining outbound queue")}c&&this._server&&this._kex.remoteExtInfoEnabled&&P0(this),a(...p)},this._queue=void 0;let l=t.messageHandlers;typeof l=="object"&&l!==null?this._handlers=l:this._handlers={},this._onPayload=N0.bind(this),this._server=!!t.server,this._banner=void 0;let f;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&&(f=t.greeting.slice(-2)===`\r
9
- `?t.greeting:`${t.greeting}\r
10
- `),typeof t.banner=="string"&&t.banner.length&&(this._banner=t.banner.slice(-2)===`\r
11
- `?t.banner:`${t.banner}\r
12
- `)}else this._hostKeys=void 0;let u=t.offer;typeof u!="object"||u===null?u=this._server?p0:h0:u.constructor!==Sd&&(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 Sd(u)),this._kex=void 0,this._strictMode=void 0,this._kexinit=void 0,this._offer=u,this._cipher=new l0(0,this._onWrite),this._decipher=void 0,this._skipNextInboundPacket=!1,this._packetRW={read:new E0,write:new y0(this)},this._hostVerifier=!this._server&&typeof t.hostVerifier=="function"?t.hostVerifier:void 0,this._parse=v0,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 p=Buffer.allocUnsafe(8+t.ident.length);p.latin1Write("SSH-2.0-",0,8),p.set(t.ident,8),this._identRaw=p,h=Buffer.allocUnsafe(p.length+2),h.set(p,0),h[h.length-2]=13,h[h.length-1]=10}else this._identRaw=Rd,h=b0;this._compatFlags=0,this._debug&&(c0?this._debug("Custom crypto binding available"):this._debug("Custom crypto binding not available")),this._debug&&this._debug(`Local ident: ${Id(this._identRaw.toString())}`),this.start=()=>{this.start=void 0,f&&this._onWrite(f),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;S0.has(t)||(t=Cd.PROTOCOL_ERROR),s[r]=we.DISCONNECT,T(s,t,++r),s.fill(0,r+=4,i),this._debug&&this._debug(`Outbound: Sending DISCONNECT (${t})`),Ie(this,this._packetRW.write.finalize(s,!0),!0)}ping(){let t=this._packetRW.write.allocStart,e=this._packetRW.write.alloc(wd.length);e.set(wd,t),this._debug&&this._debug("Outbound: Sending ping (GLOBAL_REQUEST: keepalive@openssh.com)"),Ie(this,this._packetRW.write.finalize(e))}rekey(){this._kexinit===void 0?(this._debug&&this._debug("Outbound: Initiated explicit rekey"),this._queue=[],vd(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]=we.REQUEST_SUCCESS,r.set(t,++e)):(r=this._packetRW.write.alloc(1),r[e]=we.REQUEST_SUCCESS),this._debug&&this._debug("Outbound: Sending REQUEST_SUCCESS"),Ie(this,this._packetRW.write.finalize(r))}requestFailure(){let t=this._packetRW.write.allocStart,e=this._packetRW.write.alloc(1);e[t]=we.REQUEST_FAILURE,this._debug&&this._debug("Outbound: Sending REQUEST_FAILURE"),Ie(this,this._packetRW.write.finalize(e))}channelSuccess(t){let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(5);r[e]=we.CHANNEL_SUCCESS,T(r,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_SUCCESS (r:${t})`),Ie(this,this._packetRW.write.finalize(r))}channelFailure(t){let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(5);r[e]=we.CHANNEL_FAILURE,T(r,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_FAILURE (r:${t})`),Ie(this,this._packetRW.write.finalize(r))}channelEOF(t){let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(5);r[e]=we.CHANNEL_EOF,T(r,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_EOF (r:${t})`),Ie(this,this._packetRW.write.finalize(r))}channelClose(t){let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(5);r[e]=we.CHANNEL_CLOSE,T(r,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_CLOSE (r:${t})`),Ie(this,this._packetRW.write.finalize(r))}channelWindowAdjust(t,e){let r=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(9);s[r]=we.CHANNEL_WINDOW_ADJUST,T(s,t,++r),T(s,e,r+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_WINDOW_ADJUST (r:${t}, ${e})`),Ie(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]=we.CHANNEL_DATA,T(o,t,++i),T(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})`),Ie(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]=we.CHANNEL_EXTENDED_DATA,T(a,t,++o),T(a,r,o+=4),T(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})`),Ie(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]=we.CHANNEL_OPEN_CONFIRMATION,T(o,t,++i),T(o,e,i+=4),T(o,r,i+=4),T(o,s,i+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN_CONFIRMATION (r:${t}, l:${e})`),Ie(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]=we.CHANNEL_OPEN_FAILURE,T(o,t,++i),T(o,e,i+=4),T(o,s,i+=4),i+=4,s&&(o.utf8Write(r,i,s),i+=s),T(o,0,i),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN_FAILURE (r:${t})`),Ie(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]=we.SERVICE_REQUEST,T(s,e,++r),s.utf8Write(t,r+=4,e),this._debug&&this._debug(`Outbound: Sending SERVICE_REQUEST (${t})`),Ie(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]=we.USERAUTH_REQUEST,T(c,s,++a),c.utf8Write(t,a+=4,s),T(c,14,a+=s),c.utf8Write("ssh-connection",a+=4,14),T(c,8,a+=14),c.utf8Write("password",a+=4,8),c[a+=8]=r?1:0,T(c,i,++a),Buffer.isBuffer(e)?eo(e,c,0,i,a+=4):c.utf8Write(e,a+=4,i),r?(T(c,o,a+=i),Buffer.isBuffer(r)?eo(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"),Ie(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=bd(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,l=this._kex.sessionID,f=l.length,u=(s?4+f:0)+1+4+o+4+14+4+9+1+4+a+4+c,h,p;if(s?(h=Buffer.allocUnsafe(u),p=0,T(h,f,p),h.set(l,p+=4),p+=f):(h=this._packetRW.write.alloc(u),p=this._packetRW.write.allocStart),h[p]=we.USERAUTH_REQUEST,T(h,o,++p),h.utf8Write(t,p+=4,o),T(h,14,p+=o),h.utf8Write("ssh-connection",p+=4,14),T(h,9,p+=14),h.utf8Write("publickey",p+=4,9),h[p+=9]=s?1:0,T(h,a,++p),h.utf8Write(r,p+=4,a),T(h,c,p+=a),h.set(e,p+=4),!s){this._authsQueue.push("publickey"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (publickey -- check)"),Ie(this,this._packetRW.write.finalize(h));return}s(h,A=>{if(A=xd(A,i),A===!1)throw new Error("Error while converting handshake signature");let y=A.length;p=this._packetRW.write.allocStart,h=this._packetRW.write.alloc(5+o+4+14+4+9+1+4+a+4+c+4+4+a+4+y),h[p]=we.USERAUTH_REQUEST,T(h,o,++p),h.utf8Write(t,p+=4,o),T(h,14,p+=o),h.utf8Write("ssh-connection",p+=4,14),T(h,9,p+=14),h.utf8Write("publickey",p+=4,9),h[p+=9]=1,T(h,a,++p),h.utf8Write(r,p+=4,a),T(h,c,p+=a),h.set(e,p+=4),T(h,4+a+4+y,p+=c),T(h,a,p+=4),h.utf8Write(r,p+=4,a),T(h,y,p+=a),h.set(A,p+=4),this._authsQueue.push("publickey"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (publickey)"),Ie(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=bd(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),l=Buffer.byteLength(i),f=e.length,u=this._kex.sessionID,h=u.length,p=Buffer.byteLength(r),A=Buffer.byteLength(s),y=Buffer.allocUnsafe(4+h+1+4+c+4+14+4+9+4+l+4+f+4+p+4+A),b=0;T(y,h,b),y.set(u,b+=4),y[b+=h]=we.USERAUTH_REQUEST,T(y,c,++b),y.utf8Write(t,b+=4,c),T(y,14,b+=c),y.utf8Write("ssh-connection",b+=4,14),T(y,9,b+=14),y.utf8Write("hostbased",b+=4,9),T(y,l,b+=9),y.utf8Write(i,b+=4,l),T(y,f,b+=l),y.set(e,b+=4),T(y,p,b+=f),y.utf8Write(r,b+=4,p),T(y,A,b+=p),y.utf8Write(s,b+=4,A),o(y,x=>{if(x=xd(x,a),!x)throw new Error("Error while converting handshake signature");let B=x.length,H=y.length-h-4;b=this._packetRW.write.allocStart;let C=this._packetRW.write.alloc(H+4+4+l+4+B);eo(y,C,4+h,y.length,b),T(C,4+l+4+B,b+=H),T(C,l,b+=4),C.utf8Write(i,b+=4,l),T(C,B,b+=l),C.set(x,b+=4),this._authsQueue.push("hostbased"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (hostbased)"),Ie(this,this._packetRW.write.finalize(C))})}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]=we.USERAUTH_REQUEST,T(s,e,++r),s.utf8Write(t,r+=4,e),T(s,14,r+=e),s.utf8Write("ssh-connection",r+=4,14),T(s,20,r+=14),s.utf8Write("keyboard-interactive",r+=4,20),T(s,0,r+=20),T(s,0,r+=4),this._authsQueue.push("keyboard-interactive"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (keyboard-interactive)"),Ie(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]=we.USERAUTH_REQUEST,T(s,e,++r),s.utf8Write(t,r+=4,e),T(s,14,r+=e),s.utf8Write("ssh-connection",r+=4,14),T(s,4,r+=14),s.utf8Write("none",r+=4,4),this._authsQueue.push("none"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (none)"),Ie(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]=we.USERAUTH_INFO_RESPONSE,t){T(i,t.length,++s),s+=4;for(let o=0;o<t.length;++o){let a=r[o];T(i,a,s),s+=4,a&&(i.utf8Write(t[o],s,a),s+=a)}}else T(i,0,++s);this._debug&&this._debug("Outbound: Sending USERAUTH_INFO_RESPONSE"),Ie(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]=we.GLOBAL_REQUEST,T(o,13,++i),o.utf8Write("tcpip-forward",i+=4,13),o[i+=13]=r===void 0||r===!0?1:0,T(o,s,++i),o.utf8Write(t,i+=4,s),T(o,e,i+=s),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (tcpip-forward)"),Ie(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]=we.GLOBAL_REQUEST,T(o,20,++i),o.utf8Write("cancel-tcpip-forward",i+=4,20),o[i+=20]=r===void 0||r===!0?1:0,T(o,s,++i),o.utf8Write(t,i+=4,s),T(o,e,i+=s),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (cancel-tcpip-forward)"),Ie(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]=we.GLOBAL_REQUEST,T(i,31,++s),i.utf8Write("streamlocal-forward@openssh.com",s+=4,31),i[s+=31]=e===void 0||e===!0?1:0,T(i,r,++s),i.utf8Write(t,s+=4,r),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (streamlocal-forward@openssh.com)"),Ie(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]=we.GLOBAL_REQUEST,T(i,38,++s),i.utf8Write("cancel-streamlocal-forward@openssh.com",s+=4,38),i[s+=38]=e===void 0||e===!0?1:0,T(i,r,++s),i.utf8Write(t,s+=4,r),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (cancel-streamlocal-forward@openssh.com)"),Ie(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]=we.CHANNEL_OPEN,T(c,12,++a),c.utf8Write("direct-tcpip",a+=4,12),T(c,t,a+=12),T(c,e,a+=4),T(c,r,a+=4),T(c,o,a+=4),c.utf8Write(s.dstIP,a+=4,o),T(c,s.dstPort,a+=o),T(c,i,a+=4),c.utf8Write(s.srcIP,a+=4,i),T(c,s.srcPort,a+=i),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, direct-tcpip)`),Ie(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]=we.CHANNEL_OPEN,T(a,30,++o),a.utf8Write("direct-streamlocal@openssh.com",o+=4,30),T(a,t,o+=30),T(a,e,o+=4),T(a,r,o+=4),T(a,i,o+=4),a.utf8Write(s.socketPath,o+=4,i),A0(a,0,o+=i,o+8),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, direct-streamlocal@openssh.com)`),Ie(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]=we.GLOBAL_REQUEST,T(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)"),Ie(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]=we.CHANNEL_OPEN,T(i,7,++s),i.utf8Write("session",s+=4,7),T(i,t,s+=7),T(i,e,s+=4),T(i,r,s+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, session)`),Ie(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]=we.CHANNEL_REQUEST,T(a,t,++o),T(a,13,o+=4),a.utf8Write("window-change",o+=4,13),a[o+=13]=0,T(a,r,++o),T(a,e,o+=4),T(a,i,o+=4),T(a,s,o+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, window-change)`),Ie(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=R0(a)),(!a||!a.length)&&(a=I0);let l=o.length,f=a.length,u=this._packetRW.write.allocStart,h=this._packetRW.write.alloc(21+l+4+4+4+4+4+f);if(h[u]=we.CHANNEL_REQUEST,T(h,t,++u),T(h,7,u+=4),h.utf8Write("pty-req",u+=4,7),h[u+=7]=c===void 0||c===!0?1:0,T(h,l,++u),h.utf8Write(o,u+=4,l),T(h,r,u+=l),T(h,e,u+=4),T(h,i,u+=4),T(h,s,u+=4),T(h,f,u+=4),u+=4,Array.isArray(a))for(let p=0;p<f;++p)h[u++]=a[p];else Buffer.isBuffer(a)&&h.set(a,u);this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, pty-req)`),Ie(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]=we.CHANNEL_REQUEST,T(s,t,++r),T(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)`),Ie(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]=we.CHANNEL_REQUEST,T(a,t,++o),T(a,4,o+=4),a.utf8Write("exec",o+=4,4),a[o+=4]=r===void 0||r===!0?1:0,T(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})`),Ie(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)),_d[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]=we.CHANNEL_REQUEST,T(o,t,++i),T(o,6,i+=4),o.utf8Write("signal",i+=4,6),o[i+=6]=0,T(o,s,++i),o.utf8Write(e,i+=4,s),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, signal: ${e})`),Ie(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,l=this._packetRW.write.alloc(17+i+4+a);l[c]=we.CHANNEL_REQUEST,T(l,t,++c),T(l,3,c+=4),l.utf8Write("env",c+=4,3),l[c+=3]=s===void 0||s===!0?1:0,T(l,i,++c),l.utf8Write(e,c+=4,i),T(l,a,c+=i),o?l.set(r,c+=4):l.utf8Write(r,c+=4,a),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, env: ${e}=${r})`),Ie(this,this._packetRW.write.finalize(l))}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),l=c?i.length:Buffer.byteLength(i),f=this._packetRW.write.allocStart,u=this._packetRW.write.alloc(22+a+4+l+4);u[f]=we.CHANNEL_REQUEST,T(u,t,++f),T(u,7,f+=4),u.utf8Write("x11-req",f+=4,7),u[f+=7]=r===void 0||r===!0?1:0,u[++f]=e.single?1:0,T(u,a,++f),o?u.set(s,f+=4):u.utf8Write(s,f+=4,a),T(u,l,f+=a),c?u.set(i,f+=4):u.latin1Write(i,f+=4,l),T(u,e.screen||0,f+=l),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, x11-req)`),Ie(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]=we.CHANNEL_REQUEST,T(o,t,++i),T(o,9,i+=4),o.utf8Write("subsystem",i+=4,9),o[i+=9]=r===void 0||r===!0?1:0,T(o,s,++i),o.utf8Write(e,i+=4,s),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, subsystem: ${e})`),Ie(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]=we.CHANNEL_REQUEST,T(s,t,++r),T(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)`),Ie(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]=we.GLOBAL_REQUEST,T(i,29,++s),i.utf8Write("hostkeys-prove-00@openssh.com",s+=4,29),i[s+=29]=1,++s;for(let o of r)T(i,o.length,s),eo(o,i,0,o.length,s+=4),s+=o.length;this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (hostkeys-prove-00@openssh.com)"),Ie(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]=we.SERVICE_ACCEPT,T(s,e,++r),s.utf8Write(t,r+=4,e),this._debug&&this._debug(`Outbound: Sending SERVICE_ACCEPT (${t})`),Ie(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]=we.USERAUTH_BANNER,T(a,o,++r),a.utf8Write(i,r+=4,o),T(a,0,r+=o),this._debug&&this._debug("Outbound: Sending USERAUTH_BANNER"),Ie(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]=we.CHANNEL_OPEN,T(c,15,++a),c.utf8Write("forwarded-tcpip",a+=4,15),T(c,t,a+=15),T(c,e,a+=4),T(c,r,a+=4),T(c,i,a+=4),c.utf8Write(s.boundAddr,a+=4,i),T(c,s.boundPort,a+=i),T(c,o,a+=4),c.utf8Write(s.remoteAddr,a+=4,o),T(c,s.remotePort,a+=o),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, forwarded-tcpip)`),Ie(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]=we.CHANNEL_OPEN,T(a,3,++o),a.utf8Write("x11",o+=4,3),T(a,t,o+=3),T(a,e,o+=4),T(a,r,o+=4),T(a,i,o+=4),a.utf8Write(s.originAddr,o+=4,i),T(a,s.originPort,o+=i),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, x11)`),Ie(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]=we.CHANNEL_OPEN,T(i,22,++s),i.utf8Write("auth-agent@openssh.com",s+=4,22),T(i,t,s+=22),T(i,e,s+=4),T(i,r,s+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, auth-agent@openssh.com)`),Ie(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]=we.CHANNEL_OPEN,T(a,33,++o),a.utf8Write("forwarded-streamlocal@openssh.com",o+=4,33),T(a,t,o+=33),T(a,e,o+=4),T(a,r,o+=4),T(a,i,o+=4),a.utf8Write(s.socketPath,o+=4,i),T(a,0,o+=i),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, forwarded-streamlocal@openssh.com)`),Ie(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]=we.CHANNEL_REQUEST,T(s,t,++r),T(s,11,r+=4),s.utf8Write("exit-status",r+=4,11),s[r+=11]=0,T(s,e,++r),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, exit-status: ${e})`),Ie(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)),_d[o]!==1)throw new Error(`Invalid signal: ${i}`);let a=Buffer.byteLength(o),c=s?Buffer.byteLength(s):0,l=this._packetRW.write.allocStart,f=this._packetRW.write.alloc(25+a+1+4+c+4);f[l]=we.CHANNEL_REQUEST,T(f,t,++l),T(f,11,l+=4),f.utf8Write("exit-signal",l+=4,11),f[l+=11]=0,T(f,a,++l),f.utf8Write(o,l+=4,a),f[l+=a]=r?1:0,T(f,c,++l),l+=4,c&&(f.utf8Write(s,l,c),l+=c),T(f,0,l),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, exit-signal: ${e})`),Ie(this,this._packetRW.write.finalize(f))}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]=we.USERAUTH_FAILURE,T(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"),Ie(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]=we.USERAUTH_SUCCESS,this._authsQueue.shift(),this._authenticated=!0,this._debug&&this._debug("Outbound: Sending USERAUTH_SUCCESS"),Ie(this,this._packetRW.write.finalize(e)),this._kex.negotiated.cs.compress==="zlib@openssh.com"&&(this._packetRW.read=new Nd),this._kex.negotiated.sc.compress==="zlib@openssh.com"&&(this._packetRW.write=new Bd(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]=we.USERAUTH_PK_OK,T(o,r,++i),o.utf8Write(t,i+=4,r),T(o,s,i+=r),o.set(e,i+=4),this._authsQueue.shift(),this._debug&&this._debug("Outbound: Sending USERAUTH_PK_OK"),Ie(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]=we.USERAUTH_PASSWD_CHANGEREQ,T(s,e,++r),s.utf8Write(t,r+=4,e),T(s,0,r+=e),this._debug&&this._debug("Outbound: Sending USERAUTH_PASSWD_CHANGEREQ"),Ie(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 l=0;l<r.length;++l)s+=4+Buffer.byteLength(r[l].prompt)+1;let a=this._packetRW.write.allocStart,c=this._packetRW.write.alloc(5+i+4+o+4+4+s);c[a]=we.USERAUTH_INFO_REQUEST,T(c,i,++a),a+=4,t&&(c.utf8Write(t,a,i),a+=i),T(c,o,a),a+=4,e&&(c.utf8Write(e,a,o),a+=o),T(c,0,a),T(c,r.length,a+=4),a+=4;for(let l=0;l<r.length;++l){let f=r[l],u=Buffer.byteLength(f.prompt);T(c,u,a),a+=4,u&&(c.utf8Write(f.prompt,a,u),a+=u),c[a++]=f.echo?1:0}this._debug&&this._debug("Outbound: Sending USERAUTH_INFO_REQUEST"),Ie(this,this._packetRW.write.finalize(c))}},C0=/^SSH-(2\.0|1\.99)-([^ ]+)(?: (.*))?$/;function v0(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,l=0,f=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),p=o===i?h:h.slice(o-i),A=C0.exec(p);if(!A)throw new Error("Invalid identification string");let y={greeting:o===i?"":h.slice(0,o-i),identRaw:p,versions:{protocol:A[1],software:A[2]},comments:A[3]};return this._remoteIdentRaw=Buffer.from(p),this._debug&&this._debug(`Remote ident: ${Id(p)}`),this._compatFlags=B0(y),this._buffer=void 0,this._decipher=new f0(0,m0.bind(this,{firstPacket:!0})),this._parse=k0,this._onHeader(y),this._destruct?(vd(this),t+1-s):e}if(this._server)throw new Error("Greetings from clients not permitted");if(++f>w0)throw new Error("Max greeting lines exceeded");c=!1,o=t+1,l=0}else{if(c)throw new Error("Invalid header: expected newline");if(++l>=x0)throw new Error("Header line too long")}a=t}return this._buffer||(this._buffer=kd(r,i)),t-s}function k0(n,t,e){return this._decipher.decrypt(n,t,e)}function N0(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===we.USERAUTH_SUCCESS&&!this._server&&!this._authenticated&&(this._authenticated=!0,this._kex.negotiated.cs.compress==="zlib@openssh.com"&&(this._packetRW.write=new Bd(this)),this._kex.negotiated.sc.compress==="zlib@openssh.com"&&(this._packetRW.read=new Nd));let e=g0[t];if(e===void 0){this._debug&&this._debug(`Inbound: Unsupported message type: ${t}`);return}return e(this,n)}function B0(n){let t=n.versions.software,e=0;for(let r of u0)typeof r[0]=="string"?t===r[0]&&(e|=r[1]):r[0].test(t)&&(e|=r[1]);return e}function R0(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=Va[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++]=Va.TTY_OP_END,r<e.length?kd(e,0,r):e}function P0(n){let t="ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521rsa-sha2-512,rsa-sha2-256,ssh-rsa,ssh-dss";d0&&(t=`ssh-ed25519,${t}`);let e=Buffer.byteLength(t),r=n._packetRW.write.allocStart,s=n._packetRW.write.alloc(28+e);s[r]=we.EXT_INFO,T(s,1,++r),T(s,15,r+=4),s.utf8Write("server-sig-algs",r+=4,15),T(s,e,r+=15),s.utf8Write(t,r+=4,e),n._debug&&n._debug("Outbound: Sending EXT_INFO"),Ie(n,n._packetRW.write.finalize(s))}Pd.exports=za});var Ud=lt($i=>{"use strict";var to=require("assert"),{inspect:T0}=require("util");function Td(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 Od(n,t){if(to(typeof t=="string","`thing` has to be of type string"),Array.isArray(n)){let e=n.length;return to(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)}`}$i.ERR_INTERNAL_ASSERTION=class Dd extends Error{constructor(t){super(),Error.captureStackTrace(this,Dd);let e=`This is caused by either a bug in ssh2 or incorrect usage of ssh2 internals.
13
- Please open an issue with this stack trace at https://github.com/mscdex/ssh2/issues
14
- `;this.message=t===void 0?e:`${t}
15
- ${e}`}};var O0=2**32,Ld=(()=>{try{return new Function("return 2n ** 32n")()}catch{}})();$i.ERR_OUT_OF_RANGE=class Md extends RangeError{constructor(t,e,r,s){super(),Error.captureStackTrace(this,Md),to(e,'Missing "range" argument');let i=s?t:`The value of "${t}" is out of range.`,o;Number.isInteger(r)&&Math.abs(r)>O0?o=Td(String(r)):typeof r=="bigint"?(o=String(r),(r>Ld||r<-Ld)&&(o=Td(o)),o+="n"):o=T0(r),i+=` It must be ${e}. Received ${o}`,this.message=i}};var no=class n extends TypeError{constructor(t,e,r){super(),Error.captureStackTrace(this,n),to(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} ${Od(e,"type")}`;else{let o=t.includes(".")?"property":"argument";i=`The "${t}" ${o} ${s} ${Od(e,"type")}`}i+=`. Received type ${typeof r}`,this.message=i}};$i.ERR_INVALID_ARG_TYPE=no;$i.validateNumber=function(t,e){if(typeof t!="number")throw new no(e,"number",t)}});var Fi=lt(($x,Xd)=>{"use strict";var L0=require("events"),ir=require("fs"),{constants:on}=ir,{Readable:qd,Writable:rc}=require("stream"),{inherits:Kd,types:{isDate:Xa}}=require("util"),D0=Buffer[Symbol.species],{bufferCopy:rr,bufferSlice:Jr,makeBufferParser:M0,writeUInt32BE:V}=bn(),Kn={SIZE:1,UIDGID:2,PERMISSIONS:4,ACMODTIME:8,EXTENDED:2147483648},Pe=Buffer.alloc(28),nt={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},U0=new Map(Object.values(nt).map(n=>[n,1])),$0={[nt.OK]:"No error",[nt.EOF]:"End of file",[nt.NO_SUCH_FILE]:"No such file or directory",[nt.PERMISSION_DENIED]:"Permission denied",[nt.FAILURE]:"Failure",[nt.BAD_MESSAGE]:"Bad message",[nt.NO_CONNECTION]:"No connection",[nt.CONNECTION_LOST]:"Connection lost",[nt.OP_UNSUPPORTED]:"Operation unsupported"},Ne={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},an={VERSION:2,STATUS:101,HANDLE:102,DATA:103,NAME:104,ATTRS:105,EXTENDED:201},Ce={READ:1,WRITE:2,APPEND:4,CREAT:8,TRUNC:16,EXCL:32},$d=2*1024,pt=2**32-1,F0=Buffer.from([0,0,0,5,Ne.INIT,0,0,0,3]),H0=Buffer.from([0,0,0,5,an.VERSION,0,0,0,3]),Q0=/^SSH-2.0-(?:OpenSSH|dropbear)/,Ga=256*1024,$=M0(),W0={readable:!1,writable:!1,push:n=>{},once:()=>{},on:()=>{},emit:()=>{},end:()=>{}};function Vd(){}var Ja=class extends L0{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&&Q0.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=Ga,this._maxOutPktLen=34e3,this._maxReadLen=(this._isOpenSSH?Ga:34e3)-$d,this._maxWriteLen=(this._isOpenSSH?Ga:34e3)-$d,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=W0,this.readable=!0}push(t){if(t===null){if(jd(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 at(this,"Invalid packet length");if(this._pktLen>this._maxInPktLen){let a=this._maxInPktLen;return at(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 D0(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?Y0[r]:z0[r];if(!i)return at(this,`Unknown packet type ${r}`);if(this._version===-1){if(this.server){if(r!==Ne.INIT)return at(this,`Expected INIT packet, got ${r}`)}else if(r!==an.VERSION)return at(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=Vd,this.server||Ze(this,F0)}createReadStream(t,e){if(this.server)throw new Error("Client-only method called in server mode");return new Vn(this,t,e)}createWriteStream(t,e){if(this.server)throw new Error("Client-only method called in server mode");return new yn(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:Yd(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=Ar(r),o=r.flags,a=r.nb);let c=Buffer.byteLength(t),l=9,f=Buffer.allocUnsafe(13+c+4+4+a);V(f,f.length-4,0),f[4]=Ne.OPEN;let u=this._writeReqid=this._writeReqid+1&pt;V(f,u,5),V(f,c,l),f.utf8Write(t,l+=4,c),V(f,i,l+=c),V(f,o,l+=4),a&&(l+=4,a===Pe.length?f.set(Pe,l):rr(Pe,f,0,a,l),l+=a),this._requests[u]={cb:s};let h=Ze(this,f);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);V(i,i.length-4,0),i[4]=Ne.CLOSE;let o=this._writeReqid=this._writeReqid+1&pt;V(i,o,5),V(i,r,s),i.set(t,s+=4),this._requests[o]={cb:e};let a=Ze(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");zd(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),l=i;c&&(s=a);let f=t.length,u=9,h=Buffer.allocUnsafe(13+f+8+4+s);V(h,h.length-4,0),h[4]=Ne.WRITE;let p=this._writeReqid=this._writeReqid+1&pt;V(h,p,5),V(h,f,u),h.set(t,u+=4),u+=f;for(let y=7;y>=0;--y)h[u+y]=i&255,i/=256;V(h,s,u+=8),rr(e,h,r,r+s,u+=4),this._requests[p]={cb:y=>{y?typeof o=="function"&&o(y):c?this.write(t,e,r+s,c,l+s,o):typeof o=="function"&&o(void 0,r+s)}};let A=Ze(this,h);if(this._debug){let y=A?"Sent":"Buffered";this._debug(`SFTP: Outbound: ${y} WRITE (id:${p})`)}}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");Fd(this,ir,t,e,r,s)}fastPut(t,e,r,s){if(this.server)throw new Error("Client-only method called in server mode");Fd(ir,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,l=0,f,u=0,h=e.flag||"r",p=()=>{o===0?(a=Buffer.allocUnsafe(8192),this.read(f,a,0,8192,u,A)):this.read(f,a,l,o-l,u,A)},A=(b,x)=>{let B;if(b){if(B=b.code===nt.EOF,!B)return this.close(f,()=>s&&s(b))}else B=!1;if(B||o===0&&x===0)return y();u+=x,l+=x,o!==0?l===o?y():p():(c.push(Jr(a,0,x)),p())};A._wantEOFError=!0;let y=()=>{this.close(f,b=>(o===0?a=Buffer.concat(c,l):l<o&&(a=Jr(a,0,l)),i&&(a=a.toString(i)),s&&s(b,a)))};this.open(t,h,438,(b,x)=>{if(b)return s&&s(b);f=x;let B=(H,C)=>{if(H){this.stat(t,(M,Q)=>{if(M)return this.close(f,()=>{s&&s(H)});B(null,Q)});return}if(o=C.size||0,o===0)return c=[],p();a=Buffer.allocUnsafe(o),p()};this.fstat(f,B)})}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 l=Buffer.isBuffer(e)?e:Buffer.from(""+e,r.encoding||"utf8"),f=/a/.test(o)?null:0;if(f===null){let u=(h,p)=>{if(h){this.stat(t,(A,y)=>{if(A)return this.close(c,()=>{i&&i(h)});u(null,y)});return}Za(this,c,l,0,l.length,p.size,i)};this.fstat(c,u);return}Za(this,c,l,0,l.length,f,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);V(i,i.length-4,0),i[4]=Ne.REMOVE;let o=this._writeReqid=this._writeReqid+1&pt;V(i,o,5),V(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:e};let a=Ze(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);V(a,a.length-4,0),a[4]=Ne.RENAME;let c=this._writeReqid=this._writeReqid+1&pt;V(a,c,5),V(a,s,o),a.utf8Write(t,o+=4,s),V(a,i,o+=s),a.utf8Write(e,o+=4,i),this._requests[c]={cb:r};let l=Ze(this,a);this._debug&&this._debug(`SFTP: Outbound: ${l?"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=Ar(e),s=e.flags,i=e.nb);let o=Buffer.byteLength(t),a=9,c=Buffer.allocUnsafe(13+o+4+i);V(c,c.length-4,0),c[4]=Ne.MKDIR;let l=this._writeReqid=this._writeReqid+1&pt;V(c,l,5),V(c,o,a),c.utf8Write(t,a+=4,o),V(c,s,a+=o),i&&(a+=4,i===Pe.length?c.set(Pe,a):rr(Pe,c,0,i,a),a+=i),this._requests[l]={cb:r};let f=Ze(this,c);this._debug&&this._debug(`SFTP: Outbound: ${f?"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);V(i,i.length-4,0),i[4]=Ne.RMDIR;let o=this._writeReqid=this._writeReqid+1&pt;V(i,o,5),V(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:e};let a=Ze(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 f=[],u=0,h=(p,A)=>{if(p)return r(p);this.readdir(A,e,(y,b)=>{let x=y&&y.code===nt.EOF;if(y&&!x)return this.close(A,()=>r(y));if(x)return this.close(A,B=>{if(B)return r(B);r(void 0,f)});for(let B=0;B<b.length;++B,++u)f[u]=b[B];h(void 0,A)})};return this.opendir(t,h)}let i=t.length,o=9,a=Buffer.allocUnsafe(13+i);V(a,a.length-4,0),a[4]=Ne.READDIR;let c=this._writeReqid=this._writeReqid+1&pt;V(a,c,5),V(a,i,o),a.set(t,o+=4),this._requests[c]={cb:s?(f,u)=>{if(typeof r=="function"){if(f)return r(f);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 l=Ze(this,a);this._debug&&this._debug(`SFTP: Outbound: ${l?"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);V(i,i.length-4,0),i[4]=Ne.FSTAT;let o=this._writeReqid=this._writeReqid+1&pt;V(i,o,5),V(i,r,s),i.set(t,s+=4),this._requests[o]={cb:e};let a=Ze(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);V(i,i.length-4,0),i[4]=Ne.STAT;let o=this._writeReqid=this._writeReqid+1&pt;V(i,o,5),V(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:e};let a=Ze(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);V(i,i.length-4,0),i[4]=Ne.LSTAT;let o=this._writeReqid=this._writeReqid+1&pt;V(i,o,5),V(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:e};let a=Ze(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);V(i,i.length-4,0),i[4]=Ne.OPENDIR;let o=this._writeReqid=this._writeReqid+1&pt;V(i,o,5),V(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:e};let a=Ze(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=Ar(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);V(c,c.length-4,0),c[4]=Ne.SETSTAT;let l=this._writeReqid=this._writeReqid+1&pt;V(c,l,5),V(c,o,a),c.utf8Write(t,a+=4,o),V(c,s,a+=o),i&&(a+=4,i===Pe.length?c.set(Pe,a):rr(Pe,c,0,i,a),a+=i),this._requests[l]={cb:r};let f=Ze(this,c);this._debug&&this._debug(`SFTP: Outbound: ${f?"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=Ar(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);V(c,c.length-4,0),c[4]=Ne.FSETSTAT;let l=this._writeReqid=this._writeReqid+1&pt;V(c,l,5),V(c,o,a),c.set(t,a+=4),V(c,s,a+=o),i&&(a+=4,i===Pe.length?c.set(Pe,a):rr(Pe,c,0,i,a),a+=i),this._requests[l]={cb:r};let f=Ze(this,c);this._debug&&this._debug(`SFTP: Outbound: ${f?"Buffered":"Sending"} FSETSTAT`)}futimes(t,e,r,s){return this.fsetstat(t,{atime:jr(e),mtime:jr(r)},s)}utimes(t,e,r,s){return this.setstat(t,{atime:jr(e),mtime:jr(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);V(i,i.length-4,0),i[4]=Ne.READLINK;let o=this._writeReqid=this._writeReqid+1&pt;V(i,o,5),V(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:(c,l)=>{if(typeof e=="function"){if(c)return e(c);if(!l||!l.length)return e(new Error("Response missing link info"));e(void 0,l[0].filename)}}};let a=Ze(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);V(a,a.length-4,0),a[4]=Ne.SYMLINK;let c=this._writeReqid=this._writeReqid+1&pt;V(a,c,5),this._isOpenSSH?(V(a,i,o),a.utf8Write(t,o+=4,i),V(a,s,o+=i),a.utf8Write(e,o+=4,s)):(V(a,s,o),a.utf8Write(e,o+=4,s),V(a,i,o+=s),a.utf8Write(t,o+=4,i)),this._requests[c]={cb:r};let l=Ze(this,a);this._debug&&this._debug(`SFTP: Outbound: ${l?"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);V(i,i.length-4,0),i[4]=Ne.REALPATH;let o=this._writeReqid=this._writeReqid+1&pt;V(i,o,5),V(i,r,s),i.utf8Write(t,s+=4,r),this._requests[o]={cb:(c,l)=>{if(typeof e=="function"){if(c)return e(c);if(!l||!l.length)return e(new Error("Response missing path info"));e(void 0,l[0].filename)}}};let a=Ze(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);V(c,c.length-4,0),c[4]=Ne.EXTENDED;let l=this._writeReqid=this._writeReqid+1&pt;V(c,l,5),V(c,24,a),c.utf8Write("posix-rename@openssh.com",a+=4,24),V(c,i,a+=24),c.utf8Write(t,a+=4,i),V(c,o,a+=i),c.utf8Write(e,a+=4,o),this._requests[l]={cb:r};let f=Ze(this,c);if(this._debug){let u=f?"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);V(o,o.length-4,0),o[4]=Ne.EXTENDED;let a=this._writeReqid=this._writeReqid+1&pt;V(o,a,5),V(o,19,i),o.utf8Write("statvfs@openssh.com",i+=4,19),V(o,s,i+=19),o.utf8Write(t,i+=4,s),this._requests[a]={extended:"statvfs@openssh.com",cb:e};let c=Ze(this,o);if(this._debug){let l=c?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${l} 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);V(o,o.length-4,0),o[4]=Ne.EXTENDED;let a=this._writeReqid=this._writeReqid+1&pt;V(o,a,5),V(o,20,i),o.utf8Write("fstatvfs@openssh.com",i+=4,20),V(o,s,i+=20),o.set(t,i+=4),this._requests[a]={extended:"fstatvfs@openssh.com",cb:e};let c=Ze(this,o);if(this._debug){let l=c?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${l} 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);V(c,c.length-4,0),c[4]=Ne.EXTENDED;let l=this._writeReqid=this._writeReqid+1&pt;V(c,l,5),V(c,20,a),c.utf8Write("hardlink@openssh.com",a+=4,20),V(c,i,a+=20),c.utf8Write(t,a+=4,i),V(c,o,a+=i),c.utf8Write(e,a+=4,o),this._requests[l]={cb:r};let f=Ze(this,c);if(this._debug){let u=f?"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);V(o,o.length-4,0),o[4]=Ne.EXTENDED;let a=this._writeReqid=this._writeReqid+1&pt;V(o,a,5),V(o,17,i),o.utf8Write("fsync@openssh.com",i+=4,17),V(o,s,i+=17),o.set(t,i+=4),this._requests[a]={cb:e};let c=Ze(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=Ar(e),i=e.flags,o=e.nb):typeof e=="function"&&(r=e);let a=Buffer.byteLength(t),c=9,l=Buffer.allocUnsafe(37+a+4+o);V(l,l.length-4,0),l[4]=Ne.EXTENDED;let f=this._writeReqid=this._writeReqid+1&pt;V(l,f,5),V(l,20,c),l.utf8Write("lsetstat@openssh.com",c+=4,20),V(l,a,c+=20),l.utf8Write(t,c+=4,a),V(l,i,c+=a),o&&(c+=4,o===Pe.length?l.set(Pe,c):rr(Pe,l,0,o,c),c+=o),this._requests[f]={cb:r};let u=Ze(this,l);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);V(o,o.length-4,0),o[4]=Ne.EXTENDED;let a=this._writeReqid=this._writeReqid+1&pt;V(o,a,5),V(o,23,i),o.utf8Write("expand-path@openssh.com",i+=4,23),V(o,s,i+=20),o.utf8Write(t,i+=4,s),this._requests[a]={cb:(l,f)=>{if(typeof e=="function"){if(l)return e(l);if(!f||!f.length)return e(new Error("Response missing expanded path"));e(void 0,f[0].filename)}}};let c=Ze(this,o);if(this._debug){let l=c?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${l} 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,l=Buffer.allocUnsafe(26+t.length+8+8+4+s.length+8);V(l,l.length-4,c),c+=4,l[c]=Ne.EXTENDED,++c;let f=this._writeReqid=this._writeReqid+1&pt;V(l,f,c),c+=4,V(l,9,c),c+=4,l.utf8Write("copy-data",c,9),c+=9,V(l,t.length,c),c+=4,l.set(t,c),c+=t.length;for(let h=7;h>=0;--h)l[c+h]=e&255,e/=256;c+=8;for(let h=7;h>=0;--h)l[c+h]=r&255,r/=256;c+=8,V(l,s.length,c),c+=4,l.set(s,c),c+=s.length;for(let h=7;h>=0;--h)l[c+h]=i&255,i/=256;this._requests[f]={cb:o};let u=Ze(this,l);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);V(o,o.length-4,s),s+=4,o[s]=Ne.EXTENDED,++s;let a=this._writeReqid=this._writeReqid+1&pt;V(o,a,s),s+=4,V(o,14,s),s+=4,o.utf8Write("home-directory",s,14),s+=14,V(o,i,s),s+=4,o.utf8Write(t,s,i),s+=i,this._requests[a]={cb:(l,f)=>{if(typeof e=="function"){if(l)return e(l);if(!f||!f.length)return e(new Error("Response missing home directory"));e(void 0,f[0].filename)}}};let c=Ze(this,o);if(this._debug){let l=c?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${l} 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 l of t)if(!Number.isInteger(l)||l<0||l>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 l of e)if(!Number.isInteger(l)||l<0||l>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);V(o,o.length-4,i),i+=4,o[i]=Ne.EXTENDED,++i;let a=this._writeReqid=this._writeReqid+1&pt;V(o,a,i),i+=4,V(o,30,i),i+=4,o.utf8Write("users-groups-by-id@openssh.com",i,30),i+=30,V(o,4*t.length,i),i+=4;for(let l of t)V(o,l,i),i+=4;V(o,4*e.length,i),i+=4;for(let l of e)V(o,l,i),i+=4;this._requests[a]={extended:"users-groups-by-id@openssh.com",cb:r};let c=Ze(this,o);if(this._debug){let l=c?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${l} 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);V(i,i.length-4,0),i[4]=an.HANDLE,V(i,t,5),V(i,r,s),r&&i.set(e,s+=4);let o=Ze(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(!U0.has(e))throw new Error(`Bad status code: ${e}`);r||(r="");let s=Buffer.byteLength(r),i=9,o=Buffer.allocUnsafe(17+s+4);V(o,o.length-4,0),o[4]=an.STATUS,V(o,t,5),V(o,e,i),V(o,s,i+=4),i+=4,s&&(o.utf8Write(r,i,s),i+=s),V(o,0,i);let a=Ze(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);V(c,c.length-4,0),c[4]=an.DATA,V(c,t,5),V(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 l=Ze(this,c);this._debug&&this._debug(`SFTP: Outbound: ${l?"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 f=0;f<r;++f){let u=e[f],h=!u||!u.filename||typeof u.filename!="string"?"":u.filename;s+=4+Buffer.byteLength(h);let p=!u||!u.longname||typeof u.longname!="string"?"":u.longname;if(s+=4+Buffer.byteLength(p),typeof u.attrs=="object"&&u.attrs!==null){if(i=Ar(u.attrs),s+=4+i.nb,i.nb){let A;i.nb===Pe.length?A=new Uint8Array(Pe):(A=new Uint8Array(i.nb),rr(Pe,A,0,i.nb,0)),i.bytes=A}o.push(i)}else s+=4,o.push(null)}let a=9,c=Buffer.allocUnsafe(13+s);V(c,c.length-4,0),c[4]=an.NAME,V(c,t,5),V(c,r,a),a+=4;for(let f=0;f<r;++f){let u=e[f];{let p=!u||!u.filename||typeof u.filename!="string"?"":u.filename,A=Buffer.byteLength(p);V(c,A,a),a+=4,A&&(c.utf8Write(p,a,A),a+=A)}{let p=!u||!u.longname||typeof u.longname!="string"?"":u.longname,A=Buffer.byteLength(p);V(c,A,a),a+=4,A&&(c.utf8Write(p,a,A),a+=A)}let h=o[f];h?(V(c,h.flags,a),a+=4,h.flags&&h.bytes&&(c.set(h.bytes,a),a+=h.nb)):(V(c,0,a),a+=4)}let l=Ze(this,c);this._debug&&this._debug(`SFTP: Outbound: ${l?"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=Ar(e);let r=e.flags,s=e.nb,i=9,o=Buffer.allocUnsafe(13+s);V(o,o.length-4,0),o[4]=an.ATTRS,V(o,t,5),V(o,r,i),s&&(i+=4,s===Pe.length?o.set(Pe,i):rr(Pe,o,0,s,i),i+=s);let a=Ze(this,o);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} ATTRS`)}};function q0(n){try{return Buffer.allocUnsafe(n)}catch(t){return t}}function zd(n,t,e,r,s,i,o,a){let c=n._maxReadLen,l=Math.max(s-c,0);l&&(s=c);let f=t.length,u=9,h=i,p=Buffer.allocUnsafe(13+f+8+4);V(p,p.length-4,0),p[4]=Ne.READ;let A=n._writeReqid=n._writeReqid+1&pt;V(p,A,5),V(p,f,u),p.set(t,u+=4),u+=f;for(let x=7;x>=0;--x)p[u+x]=h&255,h/=256;V(p,s,u+=8),typeof o!="function"&&(o=Vd);let y=a||{nb:0,position:i,off:r,origOff:r,len:void 0,overflow:void 0,cb:(x,B,H)=>{let C=y.len,M=y.overflow;if(x){if(o._wantEOFError||x.code!==nt.EOF)return o(x)}else{if(H>C)return o(new Error("Received more data than requested"));if(H===C&&M){y.nb+=H,y.position+=H,y.off+=H,zd(n,t,e,y.off,M,y.position,o,y);return}}H=H||0,y.origOff===0&&e.length===y.nb?B=e:B=Jr(e,y.origOff,y.origOff+y.nb+H),o(void 0,y.nb+H,B,y.position)},buffer:void 0};y.len=s,y.overflow=l,y.buffer=Jr(e,r,r+s),n._requests[A]=y;let b=Ze(n,p);n._debug&&n._debug(`SFTP: Outbound: ${b?"Buffered":"Sending"} READ`)}function Fd(n,t,e,r,s,i){let o=64,a=32768,c,l,f;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)&&(f=s.fileSize),typeof s.step=="function"&&(c=s.step),(typeof s.mode=="string"||typeof s.mode=="number")&&(l=ic(s.mode)));let u,h=0,p=0,A=!1,y,b,x,B=a*o;function H(C){if(A)return;A=!0;let M=0,Q;y||b?(Q=()=>{--M===0&&i(C)},y&&(n===ir||n.outgoing.state==="open")&&++M,b&&(t===ir||t.outgoing.state==="open")&&++M,y&&(n===ir||n.outgoing.state==="open")&&n.close(y,Q),b&&(t===ir||t.outgoing.state==="open")&&t.close(b,Q)):i(C)}n.open(e,"r",(C,M)=>{if(C)return H(C);y=M,f===void 0?n.fstat(y,Q):Q(null,{size:f});function Q(N,S){if(N){if(n!==ir){n.stat(e,(w,v)=>{if(w)return H(N);Q(null,v)});return}return H(N)}u=S.size,t.open(r,"w",(w,v)=>{if(w)return H(w);if(b=v,u<=0)return H();for(;B>u;){if(o===1){B=u;break}B-=a,--o}if(x=q0(B),x instanceof Error)return H(x);l!==void 0?t.fchmod(b,l,function G(te){if(te){t.chmod(r,l,le=>G());return}Y()}):Y();function k(G,te,le,U,R,O){if(G)return H(G);R=R||0,t.write(b,x,R,te,U,K);function K(ee){if(ee)return H(ee);if(p+=te,c&&c(p,te,u),te<O)return ne(R,U+te,O-te);if(p===u){t.close(b,ie=>{if(b=void 0,ie)return H(ie);n.close(y,Xe=>{if(y=void 0,Xe)return H(Xe);i()})});return}if(h>=u)return;let ue=h+a>u?u-h:a;ne(R,h,ue),h+=ue}}function P(G,te,le){return(U,R,O)=>{k(U,R,O,te,G,le)}}function ne(G,te,le){n.read(y,x,G,le,te,P(G,te,le))}function Y(){let G=0,te=0;for(;h<u&&G<o;){let le=h+a>u?u-h:a;ne(te,h,le),te+=le,h+=le,++G}}})}})}function Za(n,t,e,r,s,i,o){let a=typeof o=="function"?o:void 0;n.write(t,e,r,s,i,(c,l)=>{if(c)return n.close(t,()=>{a&&a(c)});l===s?n.close(t,a):(r+=l,s-=l,i+=l,Za(n,t,e,r,s,i,a))})}var io=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&on.S_IFMT)===on.S_IFDIR}isFile(){return(this.mode&on.S_IFMT)===on.S_IFREG}isBlockDevice(){return(this.mode&on.S_IFMT)===on.S_IFBLK}isCharacterDevice(){return(this.mode&on.S_IFMT)===on.S_IFCHR}isSymbolicLink(){return(this.mode&on.S_IFMT)===on.S_IFLNK}isFIFO(){return(this.mode&on.S_IFMT)===on.S_IFIFO}isSocket(){return(this.mode&on.S_IFMT)===on.S_IFSOCK}};function Ar(n){let t=0,e=0;if(typeof n=="object"&&n!==null){if(typeof n.size=="number"){t|=Kn.SIZE;let r=n.size;Pe[e++]=r/72057594037927940,Pe[e++]=r/281474976710656,Pe[e++]=r/1099511627776,Pe[e++]=r/4294967296,Pe[e++]=r/16777216,Pe[e++]=r/65536,Pe[e++]=r/256,Pe[e++]=r}if(typeof n.uid=="number"&&typeof n.gid=="number"){t|=Kn.UIDGID;let r=n.uid,s=n.gid;Pe[e++]=r>>>24,Pe[e++]=r>>>16,Pe[e++]=r>>>8,Pe[e++]=r,Pe[e++]=s>>>24,Pe[e++]=s>>>16,Pe[e++]=s>>>8,Pe[e++]=s}if(typeof n.mode=="number"||typeof n.mode=="string"){let r=ic(n.mode);t|=Kn.PERMISSIONS,Pe[e++]=r>>>24,Pe[e++]=r>>>16,Pe[e++]=r>>>8,Pe[e++]=r}if((typeof n.atime=="number"||Xa(n.atime))&&(typeof n.mtime=="number"||Xa(n.mtime))){let r=jr(n.atime),s=jr(n.mtime);t|=Kn.ACMODTIME,Pe[e++]=r>>>24,Pe[e++]=r>>>16,Pe[e++]=r>>>8,Pe[e++]=r,Pe[e++]=s>>>24,Pe[e++]=s>>>16,Pe[e++]=s>>>8,Pe[e++]=s}}return{flags:t,nb:e}}function jr(n){if(typeof n=="number"&&n===n)return n;if(Xa(n))return parseInt(n.getTime()/1e3,10);throw new Error(`Cannot parse time: ${n}`)}function ic(n){if(typeof n=="number"&&n===n)return n;if(typeof n=="string")return ic(parseInt(n,8));throw new Error(`Cannot parse mode: ${n}`)}var ec={r:Ce.READ,"r+":Ce.READ|Ce.WRITE,w:Ce.TRUNC|Ce.CREAT|Ce.WRITE,wx:Ce.TRUNC|Ce.CREAT|Ce.WRITE|Ce.EXCL,xw:Ce.TRUNC|Ce.CREAT|Ce.WRITE|Ce.EXCL,"w+":Ce.TRUNC|Ce.CREAT|Ce.READ|Ce.WRITE,"wx+":Ce.TRUNC|Ce.CREAT|Ce.READ|Ce.WRITE|Ce.EXCL,"xw+":Ce.TRUNC|Ce.CREAT|Ce.READ|Ce.WRITE|Ce.EXCL,a:Ce.APPEND|Ce.CREAT|Ce.WRITE,ax:Ce.APPEND|Ce.CREAT|Ce.WRITE|Ce.EXCL,xa:Ce.APPEND|Ce.CREAT|Ce.WRITE|Ce.EXCL,"a+":Ce.APPEND|Ce.CREAT|Ce.READ|Ce.WRITE,"ax+":Ce.APPEND|Ce.CREAT|Ce.READ|Ce.WRITE|Ce.EXCL,"xa+":Ce.APPEND|Ce.CREAT|Ce.READ|Ce.WRITE|Ce.EXCL};function Yd(n){let t=ec[n];return t!==void 0?t:null}var K0=(()=>{let n=Object.keys(ec);return t=>{for(let e=0;e<n.length;++e){let r=n[e];if(ec[r]===t)return r}return null}})();function Xr(n){let t=$.readUInt32BE();if(t===void 0)return;let e=new io;if(t&Kn.SIZE){let r=$.readUInt64BE(n);if(r===void 0)return;e.size=r}if(t&Kn.UIDGID){let r=$.readUInt32BE(),s=$.readUInt32BE();if(s===void 0)return;e.uid=r,e.gid=s}if(t&Kn.PERMISSIONS){let r=$.readUInt32BE();if(r===void 0)return;e.mode=r}if(t&Kn.ACMODTIME){let r=$.readUInt32BE(),s=$.readUInt32BE();if(s===void 0)return;e.atime=r,e.mtime=s}if(t&Kn.EXTENDED){let r=$.readUInt32BE();if(r===void 0)return;let s={};for(let i=0;i<r;++i){let o=$.readString(!0),a=$.readString();if(a===void 0)return;s[o]=a}e.extended=s}return e}function Ze(n,t){let e=Gd(n,t);return e!==void 0?(n._buffer.push(e),!1):!0}function Gd(n,t){let e=n.outgoing;if(e.state!=="open")return;if(e.window===0)return n._waitWindow=!0,n._chunkcb=Hd,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=Hd),i===0&&o===s?n._protocol.channelData(n.outgoing.id,t):n._protocol.channelData(n.outgoing.id,Jr(t,i,i+o)),i+=o}return s-i>0&&(i>0?r=Jr(t,i,s):r=t),r}function Hd(){this._chunkcb=void 0;let n=this._buffer,t=0;for(;t<n.length;){let e=n[t],r=Gd(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 at(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(),jd(n),!1}function jd(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 V0(n,t){let e=9,r=Buffer.allocUnsafe(31);V(r,r.length-4,0),r[4]=Ne.EXTENDED;let s=n._writeReqid=n._writeReqid+1&pt;V(r,s,5),V(r,18,e),r.utf8Write("limits@openssh.com",e+=4,18),n._requests[s]={extended:"limits@openssh.com",cb:t};let i=Ze(n,r);if(n._debug){let o=i?"Buffered":"Sending";n._debug(`SFTP: Outbound: ${o} limits@openssh.com`)}}var z0={[an.VERSION]:(n,t)=>{if(n._version!==-1)return at(n,"Duplicate VERSION packet");let e={};$.init(t,1);let r=$.readUInt32BE();for(;$.avail();){let s=$.readString(!0),i=$.readString(!0);if(i===void 0){r=void 0;break}e[s]=i}if($.clear(),r===void 0)return at(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 V0(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")},[an.STATUS]:(n,t)=>{$.init(t,1);let e=$.readUInt32BE(),r=$.readUInt32BE(),s=$.readString(!0);if($.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===nt.OK){i.cb();return}let o=new Error(s||$0[r]||"Unknown status");o.code=r,i.cb(o)}},[an.HANDLE]:(n,t)=>{$.init(t,1);let e=$.readUInt32BE(),r=$.readString();if($.clear(),r===void 0)return e!==void 0&&delete n._requests[e],at(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)},[an.DATA]:(n,t)=>{$.init(t,1);let e=$.readUInt32BE(),r;if(e!==void 0&&(r=n._requests[e],delete n._requests[e]),r&&typeof r.cb=="function")if(r.buffer){let s=$.readString(r.buffer);if($.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=$.readString();if($.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=$.skipString();if($.clear(),s!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received DATA (id:${e}, ${s})`);return}}return at(n,"Malformed DATA packet")},[an.NAME]:(n,t)=>{$.init(t,1);let e=$.readUInt32BE(),r;e!==void 0&&(r=n._requests[e],delete n._requests[e]);let s=$.readUInt32BE();if(s!==void 0){let i=[];for(let o=0;o<s;++o){let a=$.readString(!0),c=$.readString(!0),l=Xr(n._biOpt);if(l===void 0){i=void 0;break}i.push({filename:a,longname:c,attrs:l})}if(i!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received NAME (id:${e}, ${i.length})`),$.clear(),r&&typeof r.cb=="function"&&r.cb(void 0,i);return}}return $.clear(),at(n,"Malformed NAME packet")},[an.ATTRS]:(n,t)=>{$.init(t,1);let e=$.readUInt32BE(),r;e!==void 0&&(r=n._requests[e],delete n._requests[e]);let s=Xr(n._biOpt);if($.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 at(n,"Malformed ATTRS packet")},[an.EXTENDED]:(n,t)=>{$.init(t,1);let e=$.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:$.readUInt64BE(s),f_frsize:$.readUInt64BE(s),f_blocks:$.readUInt64BE(s),f_bfree:$.readUInt64BE(s),f_bavail:$.readUInt64BE(s),f_files:$.readUInt64BE(s),f_ffree:$.readUInt64BE(s),f_favail:$.readUInt64BE(s),f_sid:$.readUInt64BE(s),f_flag:$.readUInt64BE(s),f_namemax:$.readUInt64BE(s)};if(i.f_namemax===void 0)break;n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ${r.extended})`),$.clear(),typeof r.cb=="function"&&r.cb(void 0,i);return}case"limits@openssh.com":{let s={maxPktLen:$.readUInt64BE(),maxReadLen:$.readUInt64BE(),maxWriteLen:$.readUInt64BE(),maxOpenHandles:$.readUInt64BE()};if(s.maxOpenHandles===void 0)break;n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ${r.extended})`),$.clear(),typeof r.cb=="function"&&r.cb(void 0,s);return}case"users-groups-by-id@openssh.com":{let s=$.readUInt32BE();if(s===void 0)break;let i=new Array(s);for(let c=0;c<i.length;++c)i[c]=$.readString(!0);let o=$.readUInt32BE();if(o===void 0)break;let a=new Array(o);for(let c=0;c<a.length;++c)a[c]=$.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})`),$.clear(),typeof r.cb=="function"&&r.cb(void 0,i,a);return}default:n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ???)`),$.clear(),typeof r.cb=="function"&&r.cb();return}else{n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ???)`),$.clear();return}}return $.clear(),at(n,"Malformed EXTENDED_REPLY packet")}},Y0={[Ne.INIT]:(n,t)=>{if(n._version!==-1)return at(n,"Duplicate INIT packet");let e={};$.init(t,1);let r=$.readUInt32BE();for(;$.avail();){let s=$.readString(!0),i=$.readString(!0);if(i===void 0){r=void 0;break}e[s]=i}if($.clear(),r===void 0)return at(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})`)}Ze(n,H0),n._version=r,n._extensions=e,n.emit("ready")},[Ne.OPEN]:(n,t)=>{$.init(t,1);let e=$.readUInt32BE(),r=$.readString(!0),s=$.readUInt32BE(),i=Xr(n._biOpt);if($.clear(),i===void 0)return at(n,"Malformed OPEN packet");n._debug&&n._debug(`SFTP: Inbound: Received OPEN (id:${e})`),n.emit("OPEN",e,r,s,i)||n.status(e,nt.OP_UNSUPPORTED)},[Ne.CLOSE]:(n,t)=>{$.init(t,1);let e=$.readUInt32BE(),r=$.readString();if($.clear(),r===void 0||r.length>256)return at(n,"Malformed CLOSE packet");n._debug&&n._debug(`SFTP: Inbound: Received CLOSE (id:${e})`),n.emit("CLOSE",e,r)||n.status(e,nt.OP_UNSUPPORTED)},[Ne.READ]:(n,t)=>{$.init(t,1);let e=$.readUInt32BE(),r=$.readString(),s=$.readUInt64BE(n._biOpt),i=$.readUInt32BE();if($.clear(),i===void 0||r.length>256)return at(n,"Malformed READ packet");n._debug&&n._debug(`SFTP: Inbound: Received READ (id:${e})`),n.emit("READ",e,r,s,i)||n.status(e,nt.OP_UNSUPPORTED)},[Ne.WRITE]:(n,t)=>{$.init(t,1);let e=$.readUInt32BE(),r=$.readString(),s=$.readUInt64BE(n._biOpt),i=$.readString();if($.clear(),i===void 0||r.length>256)return at(n,"Malformed WRITE packet");n._debug&&n._debug(`SFTP: Inbound: Received WRITE (id:${e})`),n.emit("WRITE",e,r,s,i)||n.status(e,nt.OP_UNSUPPORTED)},[Ne.LSTAT]:(n,t)=>{$.init(t,1);let e=$.readUInt32BE(),r=$.readString(!0);if($.clear(),r===void 0)return at(n,"Malformed LSTAT packet");n._debug&&n._debug(`SFTP: Inbound: Received LSTAT (id:${e})`),n.emit("LSTAT",e,r)||n.status(e,nt.OP_UNSUPPORTED)},[Ne.FSTAT]:(n,t)=>{$.init(t,1);let e=$.readUInt32BE(),r=$.readString();if($.clear(),r===void 0||r.length>256)return at(n,"Malformed FSTAT packet");n._debug&&n._debug(`SFTP: Inbound: Received FSTAT (id:${e})`),n.emit("FSTAT",e,r)||n.status(e,nt.OP_UNSUPPORTED)},[Ne.SETSTAT]:(n,t)=>{$.init(t,1);let e=$.readUInt32BE(),r=$.readString(!0),s=Xr(n._biOpt);if($.clear(),s===void 0)return at(n,"Malformed SETSTAT packet");n._debug&&n._debug(`SFTP: Inbound: Received SETSTAT (id:${e})`),n.emit("SETSTAT",e,r,s)||n.status(e,nt.OP_UNSUPPORTED)},[Ne.FSETSTAT]:(n,t)=>{$.init(t,1);let e=$.readUInt32BE(),r=$.readString(),s=Xr(n._biOpt);if($.clear(),s===void 0||r.length>256)return at(n,"Malformed FSETSTAT packet");n._debug&&n._debug(`SFTP: Inbound: Received FSETSTAT (id:${e})`),n.emit("FSETSTAT",e,r,s)||n.status(e,nt.OP_UNSUPPORTED)},[Ne.OPENDIR]:(n,t)=>{$.init(t,1);let e=$.readUInt32BE(),r=$.readString(!0);if($.clear(),r===void 0)return at(n,"Malformed OPENDIR packet");n._debug&&n._debug(`SFTP: Inbound: Received OPENDIR (id:${e})`),n.emit("OPENDIR",e,r)||n.status(e,nt.OP_UNSUPPORTED)},[Ne.READDIR]:(n,t)=>{$.init(t,1);let e=$.readUInt32BE(),r=$.readString();if($.clear(),r===void 0||r.length>256)return at(n,"Malformed READDIR packet");n._debug&&n._debug(`SFTP: Inbound: Received READDIR (id:${e})`),n.emit("READDIR",e,r)||n.status(e,nt.OP_UNSUPPORTED)},[Ne.REMOVE]:(n,t)=>{$.init(t,1);let e=$.readUInt32BE(),r=$.readString(!0);if($.clear(),r===void 0)return at(n,"Malformed REMOVE packet");n._debug&&n._debug(`SFTP: Inbound: Received REMOVE (id:${e})`),n.emit("REMOVE",e,r)||n.status(e,nt.OP_UNSUPPORTED)},[Ne.MKDIR]:(n,t)=>{$.init(t,1);let e=$.readUInt32BE(),r=$.readString(!0),s=Xr(n._biOpt);if($.clear(),s===void 0)return at(n,"Malformed MKDIR packet");n._debug&&n._debug(`SFTP: Inbound: Received MKDIR (id:${e})`),n.emit("MKDIR",e,r,s)||n.status(e,nt.OP_UNSUPPORTED)},[Ne.RMDIR]:(n,t)=>{$.init(t,1);let e=$.readUInt32BE(),r=$.readString(!0);if($.clear(),r===void 0)return at(n,"Malformed RMDIR packet");n._debug&&n._debug(`SFTP: Inbound: Received RMDIR (id:${e})`),n.emit("RMDIR",e,r)||n.status(e,nt.OP_UNSUPPORTED)},[Ne.REALPATH]:(n,t)=>{$.init(t,1);let e=$.readUInt32BE(),r=$.readString(!0);if($.clear(),r===void 0)return at(n,"Malformed REALPATH packet");n._debug&&n._debug(`SFTP: Inbound: Received REALPATH (id:${e})`),n.emit("REALPATH",e,r)||n.status(e,nt.OP_UNSUPPORTED)},[Ne.STAT]:(n,t)=>{$.init(t,1);let e=$.readUInt32BE(),r=$.readString(!0);if($.clear(),r===void 0)return at(n,"Malformed STAT packet");n._debug&&n._debug(`SFTP: Inbound: Received STAT (id:${e})`),n.emit("STAT",e,r)||n.status(e,nt.OP_UNSUPPORTED)},[Ne.RENAME]:(n,t)=>{$.init(t,1);let e=$.readUInt32BE(),r=$.readString(!0),s=$.readString(!0);if($.clear(),s===void 0)return at(n,"Malformed RENAME packet");n._debug&&n._debug(`SFTP: Inbound: Received RENAME (id:${e})`),n.emit("RENAME",e,r,s)||n.status(e,nt.OP_UNSUPPORTED)},[Ne.READLINK]:(n,t)=>{$.init(t,1);let e=$.readUInt32BE(),r=$.readString(!0);if($.clear(),r===void 0)return at(n,"Malformed READLINK packet");n._debug&&n._debug(`SFTP: Inbound: Received READLINK (id:${e})`),n.emit("READLINK",e,r)||n.status(e,nt.OP_UNSUPPORTED)},[Ne.SYMLINK]:(n,t)=>{$.init(t,1);let e=$.readUInt32BE(),r=$.readString(!0),s=$.readString(!0);if($.clear(),s===void 0)return at(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,nt.OP_UNSUPPORTED)},[Ne.EXTENDED]:(n,t)=>{$.init(t,1);let e=$.readUInt32BE(),r=$.readString(!0);if(r===void 0)return $.clear(),at(n,"Malformed EXTENDED packet");let s;$.avail()&&(s=$.readRaw()),$.clear(),n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED (id:${e})`),n.emit("EXTENDED",e,r,s)||n.status(e,nt.OP_UNSUPPORTED)}},{ERR_INVALID_ARG_TYPE:G0,ERR_OUT_OF_RANGE:ro,validateNumber:j0}=Ud(),Qd=128,tn,tc=[];function X0(n){tc.length>0?tn=tc.pop():tn=Buffer.allocUnsafe(n),tn.used=0}function nc(n,t){if(!Number.isSafeInteger(n))throw j0(n,t),Number.isInteger(n)?new ro(t,">= 0 and <= 2 ** 53 - 1",n):new ro(t,"an integer",n);if(n<0)throw new ro(t,">= 0 and <= 2 ** 53 - 1",n)}function ja(n){return n+7&-8}function Vn(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,qd.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&&(nc(this.start,"start"),this.pos=this.start),this.end===void 0)this.end=1/0;else if(this.end!==1/0&&(nc(this.end,"end"),this.start!==void 0&&this.start>this.end))throw new ro("start",`<= "end" (here: ${this.end})`,this.start);this.on("end",function(){this.autoClose&&this.destroy()}),Buffer.isBuffer(this.handle)||this.open()}Kd(Vn,qd);Vn.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()}))};Vn.prototype._read=function(n){if(!Buffer.isBuffer(this.handle))return this.once("open",()=>this._read(n));if(this.destroyed)return;(!tn||tn.length-tn.used<Qd)&&X0(this.readableHighWaterMark||this._readableState.highWaterMark);let t=tn,e=Math.min(tn.length-tn.used,n),r=tn.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,tn,tn.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===tn)t.used=ja(t.used+i-e);else{let a=r+e&-8,c=ja(r+i);a-c>=Qd&&tc.push(t.slice(c,a))}i>0&&(this.bytesRead+=i,o=t.slice(r,r+i)),this.pos+=i,this.push(o)}),tn.used=ja(tn.used+e)};Vn.prototype._destroy=function(n,t){if(this._opening&&!Buffer.isBuffer(this.handle)){this.once("open",Wd.bind(null,this,t,n));return}Wd(this,t,n),this.handle=null,this._opening=!1};function Wd(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")}}Vn.prototype.close=function(n){this.destroy(null,n)};Object.defineProperty(Vn.prototype,"pending",{get(){return this.handle===null},configurable:!0});function yn(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,rc.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&&(nc(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()}Kd(yn,rc);yn.prototype._final=function(n){this.autoClose&&this.destroy(),n()};yn.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)}))};yn.prototype._write=function(n,t,e){if(!Buffer.isBuffer(n)){let r=new G0("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};yn.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 rc.prototype.destroy!="function"&&(yn.prototype.destroy=Vn.prototype.destroy);yn.prototype._destroy=Vn.prototype._destroy;yn.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()};yn.prototype.destroySoon=yn.prototype.end;Object.defineProperty(yn.prototype,"pending",{get(){return this.handle===null},configurable:!0});Xd.exports={flagsToString:K0,OPEN_MODE:Ce,SFTP:Ja,Stats:io,STATUS_CODE:nt,stringToFlags:Yd}});var fc=lt((Fx,th)=>{"use strict";var{Duplex:J0,Readable:Z0,Writable:eA}=require("stream"),{CHANNEL_EXTENDED_DATATYPE:{STDERR:Jd}}=Qn(),{bufferSlice:so}=bn(),tA=32*1024,Hi=2*1024*1024,cc=Hi/2,sc=class extends Z0{constructor(t,e){super(e),this._channel=t}_read(t){this._channel._waitChanDrain&&(this._channel._waitChanDrain=!1,this._channel.incoming.window<=cc&&lc(this._channel))}},oc=class extends eA{constructor(t){super({highWaterMark:Hi}),this._channel=t}_write(t,e,r){let s=this._channel,i=s._client._protocol,o=s.outgoing,a=o.packetSize,c=o.id,l=o.window,f=t.length,u=0;if(o.state==="open"){for(;f-u>0&&l>0;){let h=f-u;h>l&&(h=l),h>a&&(h=a),u===0&&h===f?i.channelExtData(c,t,Jd):i.channelExtData(c,so(t,u,u+h),Jd),u+=h,l-=h}if(o.window=l,f-u>0){l===0&&(s._waitWindow=!0),u>0?s._chunkErr=so(t,u,f):s._chunkErr=t,s._chunkcbErr=r;return}r()}}},ac=class extends J0{constructor(t,e,r){let s={highWaterMark:Hi,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 oc(this):this.stderr=new sc(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",eh).on("close",eh)}_read(t){this._waitChanDrain&&(this._waitChanDrain=!1,this.incoming.window<=cc&&lc(this))}_write(t,e,r){let s=this._client._protocol,i=this.outgoing,o=i.packetSize,a=i.id,c=i.window,l=t.length,f=0;if(i.state==="open"){for(;l-f>0&&c>0;){let u=l-f;u>c&&(u=c),u>o&&(u=o),f===0&&u===l?s.channelData(a,t):s.channelData(a,so(t,f,f+u)),f+=u,c-=u}if(i.window=c,l-f>0){c===0&&(this._waitWindow=!0),f>0?this._chunk=so(t,f,l):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 eh(){this.readable=!1}function lc(n){if(n.outgoing.state==="closed")return;let t=Hi-n.incoming.window;t<=0||(n.incoming.window+=t,n._client._protocol.channelWindowAdjust(n.outgoing.id,t))}th.exports={Channel:ac,MAX_WINDOW:Hi,PACKET_SIZE:tA,windowAdjust:lc,WINDOW_THRESHOLD:cc}});var hc=lt((Hx,ih)=>{"use strict";var{SFTP:nA}=Fi(),Qi=2**32-1;function nh(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 rh(n,t,e,r,s){if(typeof e=="function"){nh(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!==nA&&(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 f=e._exit;c=()=>{f.code===null?e.emit("close",f.code,f.signal,f.dump,f.desc):e.emit("close",f.code)}}}!e.readable||e.destroyed||i&&i.endEmitted?c():e.once("end",c);let l=e.stderr._readableState;!e.stderr.readable||e.stderr.destroyed||l&&l.endEmitted?e.stderr.emit("close"):e.stderr.once("end",()=>e.stderr.emit("close"))}}var dc=class{constructor(t){this._client=t,this._channels={},this._cur=-1,this._count=0}add(t){let e;if(this._cur<Qi)e=++this._cur;else if(this._count===0)this._cur=0,e=0;else{let r=this._channels;for(let s=0;s<Qi;++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>=Qi||!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>=Qi||!isFinite(t))throw new Error(`Invalid channel id: ${t}`);return this._channels[t]}remove(t){if(typeof t!="number"||t<0||t>=Qi||!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];rh(s,o,a._channel||a,t,!0)}}},uc=(()=>{let n=Object.prototype.toString;return t=>n.call(t)==="[object RegExp]"})();function rA(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 l=a[c];if(typeof l=="string"){if(!l||s.indexOf(l)!==-1)continue;if(e.indexOf(l)===-1)throw new Error(`Unsupported algorithm: ${l}`);s===t&&(s=s.slice()),s.push(l)}else if(uc(l))for(let f=0;f<e.length;++f){let u=e[f];if(l.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 l=a[c];if(typeof l=="string"){if(!l||s.indexOf(l)!==-1)continue;if(e.indexOf(l)===-1)throw new Error(`Unsupported algorithm: ${l}`);s===t&&(s=s.slice()),s.unshift(l)}else if(uc(l))for(let f=e.length;f>=0;--f){let u=e[f];if(l.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 l=a[c];if(typeof l=="string"){if(!l)continue;let f=s.indexOf(l);if(f===-1)continue;s===t&&(s=s.slice()),s.splice(f,1)}else if(uc(l))for(let f=0;f<s.length;++f)l.test(s[f])&&(s===t&&(s=s.slice()),s.splice(f,1),--f)}break}}return s}return t}ih.exports={ChannelManager:dc,generateAlgorithmList:rA,onChannelOpenFailure:nh,onCHANNEL_CLOSE:rh,isWritable:n=>n&&n.writable&&n._readableState&&n._readableState.ended===!1}});var _c=lt((Qx,wh)=>{"use strict";var{createHash:iA,getHashes:sA,randomFillSync:oA}=require("crypto"),{Socket:aA}=require("net"),{lookup:cA}=require("dns"),lA=require("events"),fA=sA(),{COMPAT:Sh,CHANNEL_EXTENDED_DATATYPE:{STDERR:uA},CHANNEL_OPEN_FAILURE:Wi,DEFAULT_CIPHER:sh,DEFAULT_COMPRESSION:oh,DEFAULT_KEX:ah,DEFAULT_MAC:ch,DEFAULT_SERVER_HOST_KEY:lh,DISCONNECT_REASON:fh,DISCONNECT_REASON_BY_VALUE:dA,SUPPORTED_CIPHER:hA,SUPPORTED_COMPRESSION:pA,SUPPORTED_KEX:mA,SUPPORTED_MAC:gA,SUPPORTED_SERVER_HOST_KEY:AA}=Qn(),{init:EA}=Zn(),yA=Ya(),{parseKey:co}=nr(),{SFTP:_A}=Fi(),{bufferCopy:uh,makeBufferParser:bh,makeError:SA,readUInt32BE:bA,sigSSHToASN1:xA,writeUInt32BE:pc}=bn(),{AgentContext:dh,createAgent:hh,isAgent:ph}=Ta(),{Channel:xh,MAX_WINDOW:lo,PACKET_SIZE:fo,windowAdjust:mh,WINDOW_THRESHOLD:gh}=fc(),{ChannelManager:wA,generateAlgorithmList:qi,isWritable:Dt,onChannelOpenFailure:IA,onCHANNEL_CLOSE:CA}=hc(),oo=bh(),ao=bh(),Ki=/^OpenSSH_(?:(?![0-4])\d)|(?:\d{2,})/,Ec=n=>{},yc=class extends lA{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&&Dt(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=qi(t.algorithms.kex,ah,mA),e.kex!==ah&&(r=!1),e.serverHostKey=qi(t.algorithms.serverHostKey,lh,AA),e.serverHostKey!==lh&&(r=!1),e.cs.cipher=qi(t.algorithms.cipher,sh,hA),e.cs.cipher!==sh&&(r=!1),e.cs.mac=qi(t.algorithms.hmac,ch,gA),e.cs.mac!==ch&&(r=!1),e.cs.compress=qi(t.algorithms.compress,oh,pA),e.cs.compress!==oh&&(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=hh(t.agent):ph(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 wA(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=co(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 U=t.hostVerifier,R;fA.indexOf(t.hostHash)!==-1&&(R=t.hostHash),c=(O,K)=>{R&&(O=iA(R).update(O).digest("hex"));let ee=U(O,K);ee!==void 0&&K(ee)}}let l=this._sock=t.sock||new aA,f=!1,u=!1;this._protocol&&this._protocol.cleanup();let h=i?(U,R,O)=>{i(`Debug output from server: ${JSON.stringify(O)}`)}:void 0,p,A=this._protocol=new yA({ident:this.config.ident,offer:r?void 0:e,onWrite:U=>{Dt(l)&&l.write(U)},onError:U=>{U.level==="handshake"&&clearTimeout(this._readyTimeout),A._destruct||l.removeAllListeners("data"),this.emit("error",U);try{l.end()}catch{}},onHeader:U=>{u=!0,this._remoteVer=U.versions.software,U.greeting&&this.emit("greeting",U.greeting)},onHandshakeComplete:U=>{this.emit("handshake",U),f||(f=!0,A.service("ssh-userauth"))},debug:i,hostVerifier:c,messageHandlers:{DEBUG:h,DISCONNECT:(U,R,O)=>{if(R!==fh.BY_APPLICATION){O||(O=dA[R],O===void 0&&(O=`Unexpected disconnection reason: ${R}`));let K=new Error(O);K.code=R,this.emit("error",K)}l.end()},SERVICE_ACCEPT:(U,R)=>{R==="ssh-userauth"&&G()},EXT_INFO:(U,R)=>{if(p===void 0){for(let O of R)if(O.name==="server-sig-algs"){p=O.algs;return}p=null}},USERAUTH_BANNER:(U,R)=>{this.emit("banner",R)},USERAUTH_SUCCESS:U=>{C(),clearTimeout(this._readyTimeout),this.emit("ready")},USERAUTH_FAILURE:(U,R,O)=>{if(S.keyAlgos){let K=S.keyAlgos[0][0];if(i&&i(`Client: ${S.type} (${K}) auth failed`),S.keyAlgos.shift(),S.keyAlgos.length){let[ee,ue]=S.keyAlgos[0];switch(S.type){case"agent":A.authPK(S.username,S.agentCtx.currentKey(),ee);return;case"publickey":A.authPK(S.username,S.key,ee);return;case"hostbased":A.authHostbased(S.username,S.key,S.localHostname,S.localUsername,ee,(ie,Xe)=>{let dt=S.key.sign(ie,ue);if(dt instanceof Error)return dt.message=`Error while signing with key: ${dt.message}`,dt.level="client-authentication",this.emit("error",dt),G();Xe(dt)});return}}else S.keyAlgos=void 0}if(S.type==="agent"){let K=S.agentCtx.pos();return i&&i(`Client: Agent key #${K+1} failed`),te()}i&&i(`Client: ${S.type} auth failed`),w=O,v=R,G()},USERAUTH_PASSWD_CHANGEREQ:(U,R)=>{S.type==="password"&&this.emit("change password",R,O=>{A.authPassword(this.config.username,this.config.password,O)})},USERAUTH_PK_OK:U=>{let R,O;if(S.keyAlgos&&([R,O]=S.keyAlgos[0]),S.type==="agent"){let K=S.agentCtx.currentKey();A.authPK(S.username,K,R,(ee,ue)=>{let ie={hash:O};S.agentCtx.sign(K,ee,ie,(Xe,dt)=>{if(Xe)Xe.level="agent",this.emit("error",Xe);else return ue(dt);te()})})}else S.type==="publickey"&&A.authPK(S.username,S.key,R,(K,ee)=>{let ue=S.key.sign(K,O);if(ue instanceof Error)return ue.message=`Error signing data with key: ${ue.message}`,ue.level="client-authentication",this.emit("error",ue),G();ee(ue)})},USERAUTH_INFO_REQUEST:(U,R,O,K)=>{if(S.type==="keyboard-interactive"){if((Array.isArray(K)?K.length:0)===0){i&&i("Client: Sending automatic USERAUTH_INFO_RESPONSE"),A.authInfoRes();return}S.prompt(R,O,"",K,ue=>{A.authInfoRes(ue)})}},REQUEST_SUCCESS:(U,R)=>{o.length&&o.shift()(!1,R)},REQUEST_FAILURE:U=>{o.length&&o.shift()(!0)},GLOBAL_REQUEST:(U,R,O,K)=>{R==="hostkeys-00@openssh.com"?(RA(this,K,(ee,ue)=>{ee||this.emit("hostkeys",ue)}),O&&A.requestSuccess()):O&&A.requestFailure()},CHANNEL_OPEN:(U,R)=>{NA(this,R)},CHANNEL_OPEN_CONFIRMATION:(U,R)=>{let O=this._chanMgr.get(R.recipient);if(typeof O!="function")return;let K=O.type==="sftp",ue={type:K?"session":O.type,incoming:{id:R.recipient,window:lo,packetSize:fo,state:"open"},outgoing:{id:R.sender,window:R.window,packetSize:R.packetSize,state:"open"}},ie=K?new _A(this,ue,{debug:i}):new xh(this,ue);this._chanMgr.update(R.recipient,ie),O(void 0,ie)},CHANNEL_OPEN_FAILURE:(U,R,O,K)=>{let ee=this._chanMgr.get(R);if(typeof ee!="function")return;IA(this,R,{reason:O,description:K},ee)},CHANNEL_DATA:(U,R,O)=>{let K=this._chanMgr.get(R);if(!(typeof K!="object"||K===null)&&K.incoming.window!==0){if(K.incoming.window-=O.length,K.push(O)===!1){K._waitChanDrain=!0;return}K.incoming.window<=gh&&mh(K)}},CHANNEL_EXTENDED_DATA:(U,R,O,K)=>{if(K!==uA)return;let ee=this._chanMgr.get(R);if(!(typeof ee!="object"||ee===null)&&ee.incoming.window!==0){if(ee.incoming.window-=O.length,!ee.stderr.push(O)){ee._waitChanDrain=!0;return}ee.incoming.window<=gh&&mh(ee)}},CHANNEL_WINDOW_ADJUST:(U,R,O)=>{let K=this._chanMgr.get(R);typeof K!="object"||K===null||(K.outgoing.window+=O,K._waitWindow&&(K._waitWindow=!1,K._chunk?K._write(K._chunk,null,K._chunkcb):K._chunkcb?K._chunkcb():K._chunkErr?K.stderr._write(K._chunkErr,null,K._chunkcbErr):K._chunkcbErr&&K._chunkcbErr()))},CHANNEL_SUCCESS:(U,R)=>{let O=this._chanMgr.get(R);typeof O!="object"||O===null||(this._resetKA(),O._callbacks.length&&O._callbacks.shift()(!1))},CHANNEL_FAILURE:(U,R)=>{let O=this._chanMgr.get(R);typeof O!="object"||O===null||(this._resetKA(),O._callbacks.length&&O._callbacks.shift()(!0))},CHANNEL_REQUEST:(U,R,O,K,ee)=>{let ue=this._chanMgr.get(R);if(typeof ue!="object"||ue===null)return;let ie=ue._exit;if(ie.code===void 0){switch(O){case"exit-status":ue.emit("exit",ie.code=ee);return;case"exit-signal":ue.emit("exit",ie.code=null,ie.signal=`SIG${ee.signal}`,ie.dump=ee.coreDumped,ie.desc=ee.errorMessage);return}K&&U.channelFailure(ue.outgoing.id)}},CHANNEL_EOF:(U,R)=>{let O=this._chanMgr.get(R);typeof O!="object"||O===null||O.incoming.state==="open"&&(O.incoming.state="eof",O.readable&&O.push(null),O.stderr.readable&&O.stderr.push(null))},CHANNEL_CLOSE:(U,R)=>{CA(this,R,this._chanMgr.get(R))}}});l.pause();let y=this.config.keepaliveInterval,b=this.config.keepaliveCountMax,x=0,B,H=()=>{if(++x>b){if(clearInterval(B),l.readable){let U=new Error("Keepalive timeout");U.level="client-timeout",this.emit("error",U),l.destroy()}return}Dt(l)?(o.push(C),A.ping()):clearInterval(B)};function C(){y>0&&(x=0,clearInterval(B),Dt(l)&&(B=setInterval(H,y)))}this._resetKA=C;let M=(()=>{let U=!1;return()=>{if(!U&&(U=!0,N&&!u)){let R=SA("Connection lost before handshake","protocol",!0);this.emit("error",R)}}})(),Q=(()=>{let U=!1;return()=>{U||(U=!0,N=!0,i&&i("Socket connected"),this.emit("connect"),EA.then(()=>{A.start(),l.on("data",R=>{try{A.parse(R,0,R.length)}catch(O){this.emit("error",O);try{Dt(l)&&l.end()}catch{}}}),l.stderr&&typeof l.stderr.resume=="function"&&l.stderr.resume(),l.resume()}).catch(R=>{this.emit("error",R);try{Dt(l)&&l.end()}catch{}}))}})(),N=!1;l.on("connect",Q).on("timeout",()=>{this.emit("timeout")}).on("error",U=>{i&&i(`Socket error: ${U.message}`),clearTimeout(this._readyTimeout),U.level="client-socket",this.emit("error",U)}).on("end",()=>{i&&i("Socket ended"),M(),A.cleanup(),clearTimeout(this._readyTimeout),clearInterval(B),this.emit("end")}).on("close",()=>{i&&i("Socket closed"),M(),A.cleanup(),clearTimeout(this._readyTimeout),clearInterval(B),this.emit("close");let U=o;o=this._callbacks=[];let R=new Error("No response from server");for(let O=0;O<U.length;++O)U[O](R);this._chanMgr.cleanup(R)});let S,w=null,v=null,k=["none"];this.config.password!==void 0&&k.push("password"),a!==void 0&&k.push("publickey"),this._agent!==void 0&&k.push("agent"),this.config.tryKeyboard&&k.push("keyboard-interactive"),a!==void 0&&this.config.localHostname!==void 0&&this.config.localUsername!==void 0&&k.push("hostbased"),Array.isArray(s)?s=_h(s):typeof s!="function"&&(s=_h(k));let P=!1,ne=U=>{if(!P){if(P=!0,U===!1){let R=new Error("All configured authentication methods failed");R.level="client-authentication",this.emit("error",R),this.end();return}if(typeof U=="string"){let R=U;if(k.indexOf(R)===-1)return Y(`Authentication method not allowed: ${R}`);let O=this.config.username;switch(R){case"password":U={type:R,username:O,password:this.config.password};break;case"publickey":U={type:R,username:O,key:a};break;case"hostbased":U={type:R,username:O,key:a,localHostname:this.config.localHostname,localUsername:this.config.localUsername};break;case"agent":U={type:R,username:O,agentCtx:new dh(this._agent)};break;case"keyboard-interactive":U={type:R,username:O,prompt:(...K)=>this.emit("keyboard-interactive",...K)};break;case"none":U={type:R,username:O};break;default:return Y(`Skipping unsupported authentication method: ${U}`)}}else{if(typeof U!="object"||U===null)return Y(`Skipping invalid authentication attempt: ${U}`);{let R=U.username;if(typeof R!="string")return Y(`Skipping invalid authentication attempt: ${U}`);let O=U.type;switch(O){case"password":{let{password:K}=U;if(typeof K!="string"&&!Buffer.isBuffer(K))return Y("Skipping invalid password auth attempt");U={type:O,username:R,password:K};break}case"publickey":{let K=co(U.key,U.passphrase);if(K instanceof Error)return Y("Skipping invalid key auth attempt");if(!K.isPrivateKey())return Y("Skipping non-private key");U={type:O,username:R,key:K};break}case"hostbased":{let{localHostname:K,localUsername:ee}=U,ue=co(U.key,U.passphrase);if(ue instanceof Error||typeof K!="string"||typeof ee!="string")return Y("Skipping invalid hostbased auth attempt");if(!ue.isPrivateKey())return Y("Skipping non-private key");U={type:O,username:R,key:ue,localHostname:K,localUsername:ee};break}case"agent":{let K=U.agent;if(typeof K=="string"&&K.length)K=hh(K);else if(!ph(K))return Y(`Skipping invalid agent: ${U.agent}`);U={type:O,username:R,agentCtx:new dh(K)};break}case"keyboard-interactive":{let{prompt:K}=U;if(typeof K!="function")return Y("Skipping invalid keyboard-interactive auth attempt");U={type:O,username:R,prompt:K};break}case"none":U={type:O,username:R};break;default:return Y(`Skipping unsupported authentication method: ${U}`)}}}S=U;try{let R=S.username;switch(S.type){case"password":A.authPassword(R,S.password);break;case"publickey":{let O;if(S.keyAlgos=Ac(this,S.key,p),S.keyAlgos)if(S.keyAlgos.length)O=S.keyAlgos[0][0];else return Y("Skipping key authentication (no mutual hash algorithm)");A.authPK(R,S.key,O);break}case"hostbased":{let O,K;if(S.keyAlgos=Ac(this,S.key,p),S.keyAlgos)if(S.keyAlgos.length)[O,K]=S.keyAlgos[0];else return Y("Skipping hostbased authentication (no mutual hash algorithm)");A.authHostbased(R,S.key,S.localHostname,S.localUsername,O,(ee,ue)=>{let ie=S.key.sign(ee,K);if(ie instanceof Error)return ie.message=`Error while signing with key: ${ie.message}`,ie.level="client-authentication",this.emit("error",ie),G();ue(ie)});break}case"agent":S.agentCtx.init(O=>{if(O)return O.level="agent",this.emit("error",O),G();te()});break;case"keyboard-interactive":A.authKeyboard(R);break;case"none":A.authNone(R);break}}finally{P=!1}}};function Y(U){i&&i(U),process.nextTick(G)}function G(){P=!1;let U=s(v,w,ne);P||U===void 0||ne(U)}let te=()=>{if(S.type==="agent"){let U=S.agentCtx.nextKey();if(U===!1)i&&i("Agent: No more keys left to try"),i&&i("Client: agent auth failed"),G();else{let R=S.agentCtx.pos(),O;if(S.keyAlgos=Ac(this,U,p),S.keyAlgos)if(S.keyAlgos.length)O=S.keyAlgos[0][0];else{i&&i(`Agent: Skipping key #${R+1} (no mutual hash algorithm)`),te();return}i&&i(`Agent: Trying key #${R+1}`),A.authPK(S.username,U,O)}}},le=()=>{this.config.readyTimeout>0&&(this._readyTimeout=setTimeout(()=>{let U=new Error("Timed out while waiting for handshake");U.level="client-timeout",this.emit("error",U),l.destroy()},this.config.readyTimeout))};if(t.sock)le(),typeof l.connecting=="boolean"&&l.connecting||Q();else{let U=this.config.host,R=this.config.forceIPv4,O=this.config.forceIPv6;i&&i(`Client: Trying ${U} on port ${this.config.port} ...`);let K=()=>{le(),l.connect({host:U,port:this.config.port,localAddress:this.config.localAddress,localPort:this.config.localPort}),l.setMaxListeners(0),l.setTimeout(typeof t.timeout=="number"?t.timeout:0)};!R&&!O||R&&O?K():cA(U,R?4:6,(ee,ue,ie)=>{if(ee){let Xe=R?"IPv4":"IPv6",dt=new Error(`Error while looking up ${Xe} address for '${U}': ${ee}`);clearTimeout(this._readyTimeout),dt.level="client-dns",this.emit("error",dt),this.emit("close");return}U=ue,K()})}return this}end(){return this._sock&&Dt(this._sock)&&(this._protocol.disconnect(fh.BY_APPLICATION),this._sock.end()),this}destroy(){return this._sock&&Dt(this._sock)&&this._sock.destroy(),this}exec(t,e,r){if(!this._sock||!Dt(this._sock))throw new Error("Not connected");typeof e=="function"&&(r=e,e={});let s={allowHalfOpen:e.allowHalfOpen!==!1};return Zr(this,"session",s,(i,o)=>{if(i){r(i);return}let a=[];function c(l){if(l){o.close(),r(l);return}a.length&&a.shift()()}(this.config.allowAgentFwd===!0||e&&e.agentForward===!0&&this._agent!==void 0)&&a.push(()=>yh(o,c)),typeof e=="object"&&e!==null&&(typeof e.env=="object"&&e.env!==null&&mc(o,e.env),(typeof e.pty=="object"&&e.pty!==null||e.pty===!0)&&a.push(()=>Eh(o,e.pty,c)),(typeof e.x11=="object"&&e.x11!==null||e.x11==="number"||e.x11===!0)&&a.push(()=>Ah(o,e.x11,c))),a.push(()=>kA(o,t,e,r)),a.shift()()}),this}shell(t,e,r){if(!this._sock||!Dt(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),Zr(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(()=>yh(i,a)),t!==!1&&o.push(()=>Eh(i,t,a)),typeof e=="object"&&e!==null&&(typeof e.env=="object"&&e.env!==null&&mc(i,e.env),(typeof e.x11=="object"&&e.x11!==null||e.x11==="number"||e.x11===!0)&&o.push(()=>Ah(i,e.x11,a))),o.push(()=>vA(i,r)),o.shift()()}),this}subsys(t,e){if(!this._sock||!Dt(this._sock))throw new Error("Not connected");return Zr(this,"session",(r,s)=>{if(r){e(r);return}gc(s,t,(i,o)=>{if(i){e(i);return}e(void 0,o)})}),this}forwardIn(t,e,r){if(!this._sock||!Dt(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=bA(o,0),this._protocol._compatFlags&Sh.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||!Dt(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||!Dt(this._sock))throw new Error("Not connected");let o={srcIP:t,srcPort:e,dstIP:r,dstPort:s};return typeof i!="function"&&(i=Ec),Zr(this,"direct-tcpip",o,i),this}openssh_noMoreSessions(t){if(!this._sock||!Dt(this._sock))throw new Error("Not connected");let e=typeof t=="function";return!this.config.strictVendor||this.config.strictVendor&&Ki.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||!Dt(this._sock))throw new Error("Not connected");let r=typeof e=="function";return!this.config.strictVendor||this.config.strictVendor&&Ki.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||!Dt(this._sock))throw new Error("Not connected");let r=typeof e=="function";return!this.config.strictVendor||this.config.strictVendor&&Ki.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||!Dt(this._sock))throw new Error("Not connected");return typeof e!="function"&&(e=Ec),!this.config.strictVendor||this.config.strictVendor&&Ki.test(this._remoteVer)?(Zr(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||!Dt(this._sock))throw new Error("Not connected");return typeof t=="function"&&(e=t,t=void 0),Zr(this,"sftp",(r,s)=>{if(r){e(r);return}let i=(o,a)=>{if(o){e(o);return}function c(){s.removeListener("ready",l),s.removeListener("error",f),s.removeListener("exit",u),s.removeListener("close",u)}function l(){c(),e(void 0,s)}function f(h){c(),e(h)}function u(h,p){c();let A;typeof h=="number"?A=`Received exit code ${h} while establishing SFTP session`:p!==void 0?A=`Received signal ${p} while establishing SFTP session`:A="Received unexpected SFTP session termination";let y=new Error(A);y.code=h,y.signal=p,e(y)}s.on("ready",l).on("error",f).on("exit",u).on("close",u),s._init()};typeof t=="object"&&t!==null?mc(s,t,o=>{if(o){e(o);return}gc(s,"sftp",i)}):gc(s,"sftp",i)}),this}setNoDelay(t){return this._sock&&typeof this._sock.setNoDelay=="function"&&this._sock.setNoDelay(t),this}};function Zr(n,t,e,r){let s=lo,i=fo;typeof e=="function"&&(r=e,e={});let o=(c,l)=>{r(c,l)};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 Ah(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=BA());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 Eh(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 l=typeof e=="function";if(n.outgoing.state!=="open"){l&&e(new Error("Channel is not open"));return}l&&n._callbacks.push(f=>{if(f){e(f!==!0?f:new Error("Unable to request a pseudo-terminal"));return}e()}),n._client._protocol.pty(n.outgoing.id,r,s,o,i,a,c,l)}function yh(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 vA(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 kA(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 mc(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 gc(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 NA(n,t){let e=-1,r,s=()=>{let c={type:t.type,incoming:{id:e,window:lo,packetSize:fo,state:"open"},outgoing:{id:t.sender,window:t.window,packetSize:t.packetSize,state:"open"}},l=new xh(n,c);return n._chanMgr.update(e,l),n._protocol.channelOpenConfirm(t.sender,e,lo,fo),l},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,l)=>{if(c)return i();let f=s();f.pipe(l).pipe(f)});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 BA=(()=>{let n=Buffer.allocUnsafe(16);return()=>(oA(n,0,16),n.hexSlice(0,16))})();function _h(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 RA(n,t,e){if(!n._sock||!Dt(n._sock))return;if(typeof e!="function"&&(e=Ec),!Array.isArray(t))throw new TypeError("Invalid keys argument type");let r=[];for(let s of t){let i=co(s);if(i instanceof Error)throw i;r.push(i)}if(!n.config.strictVendor||n.config.strictVendor&&Ki.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(oo.init(i,0);oo.avail()&&a!==r.length;){let c=r[a++],l=c.getPublicSSH(),f=oo.readString();ao.init(f,0);let u=ao.readString(!0),h=ao.readString(),p;if(u!==c.type)if(c.type==="ssh-rsa")switch(u){case"rsa-sha2-256":p="sha256";break;case"rsa-sha2-512":p="sha512";break;default:continue}else continue;let A=n._protocol._kex.sessionID,y=Buffer.allocUnsafe(37+A.length+4+l.length),b=0;pc(y,29,b),y.utf8Write("hostkeys-prove-00@openssh.com",b+=4,29),pc(y,A.length,b+=29),uh(A,y,0,A.length,b+=4),pc(y,l.length,b+=A.length),uh(l,y,0,l.length,b+=4),(h=xA(h,u))&&c.verify(y,h,p)===!0&&o.push(c)}ao.clear(),oo.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 Ac(n,t,e){switch(t.type){case"ssh-rsa":if(n._protocol._compatFlags&Sh.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"]]}}wh.exports=yc});var Ch=lt(Ih=>{"use strict";var{Agent:bc}=require("http"),{Agent:PA}=require("https"),{connect:TA}=require("tls"),Sc;for(let n of[bc,PA]){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;Sc===void 0&&(Sc=_c());let l=new Sc,f=!1;l.on("ready",()=>{l.forwardOut(i,o,a,c,(u,h)=>{if(f=!0,u)return l.end(),s(u);h.once("close",()=>l.end()),s(null,OA(h,n,r))})}).on("error",s).on("close",()=>{f||s(new Error("Unexpected connection close"))}).connect(this._connectCfg)}}Ih[n===bc?"SSHTTPAgent":"SSHTTPSAgent"]=t}function Vi(){}function OA(n,t,e){if(t===bc)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=TA(e),s=(()=>{let i=!1;return()=>{i||(i=!0,n.isPaused()&&n.resume())}})();return r.on("end",s).on("close",s),r}});var kh=lt((qx,Cc)=>{"use strict";var{Server:LA}=require("net"),Yi=require("events"),{listenerCount:Xt}=Yi,{CHANNEL_OPEN_FAILURE:ei,DEFAULT_CIPHER:DA,DEFAULT_COMPRESSION:MA,DEFAULT_KEX:UA,DEFAULT_MAC:$A,DEFAULT_SERVER_HOST_KEY:FA,DISCONNECT_REASON:ti,DISCONNECT_REASON_BY_VALUE:HA,SUPPORTED_CIPHER:QA,SUPPORTED_COMPRESSION:WA,SUPPORTED_KEX:qA,SUPPORTED_MAC:KA,SUPPORTED_SERVER_HOST_KEY:VA}=Qn(),{init:zA}=Zn(),{KexInit:YA}=zs(),{parseKey:vh}=nr(),GA=Ya(),{SFTP:jA}=Fi(),{writeUInt32BE:XA}=bn(),{Channel:ni,MAX_WINDOW:sr,PACKET_SIZE:or,windowAdjust:JA,WINDOW_THRESHOLD:ZA}=fc(),{ChannelManager:eE,generateAlgorithmList:zi,isWritable:uo,onChannelOpenFailure:tE,onCHANNEL_CLOSE:nE}=hc(),rE=10,ar=class extends Yi{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)}},ho=class extends ar{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)}},wc=class extends ar{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?ar.prototype.accept.call(this):(this._initialResponse=!0,this._protocol.authPKOK(this.key.algo,this.key.data))}},Ic=class extends ar{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}},po=class extends ar{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)}},Tn=class extends Yi{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:sr,packetSize:or,state:"open"},outgoing:{id:e.sender,window:e.window,packetSize:e.packetSize,state:"open"}}}},hn=class extends Yi{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=zi(o.serverHostKey,FA,VA);for(let h=0;h<i.length;++h){let p;if(Buffer.isBuffer(i[h])||typeof i[h]=="string"?p=vh(i[h]):p=vh(i[h].key,i[h].passphrase),p instanceof Error)throw new Error(`Cannot parse privateKey: ${p.message}`);if(Array.isArray(p)&&(p=p[0]),p.getPrivatePEM()===null)throw new Error("privateKey value contains an invalid private key");if(!s.includes(p.type))if(p.type==="ssh-rsa"){let A=a.indexOf("ssh-rsa"),y=a.indexOf("rsa-sha2-256"),b=a.indexOf("rsa-sha2-512");A===-1&&(A=1/0),[A,y,b].sort(iE).forEach(x=>{if(x===-1)return;let B;switch(x){case A:B="ssh-rsa";break;case y:B="rsa-sha2-256";break;case b:B="rsa-sha2-512";break;default:return}r[B]=p,s.push(B)})}else r[p.type]=p,s.push(p.type)}let c={kex:zi(o.kex,UA,qA).concat(["kex-strict-s-v00@openssh.com"]),serverHostKey:s,cs:{cipher:zi(o.cipher,DA,QA),mac:zi(o.hmac,$A,KA),compress:zi(o.compress,MA,WA),lang:[]},sc:void 0};c.sc=c.cs,typeof e=="function"&&this.on("connection",e);let l=typeof t.debug=="function"?t.debug:void 0,f=t.ident?Buffer.from(t.ident):void 0,u=new YA(c);this._srv=new LA(h=>{if(this._connections>=this.maxConnections){h.destroy();return}++this._connections,h.once("close",()=>{--this._connections});let p;if(l){let A=`[${process.hrtime().join(".")}] `;p=y=>{l(`${A}${y}`)}}new mo(h,r,f,u,p,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}};hn.KEEPALIVE_CLIENT_INTERVAL=15e3;hn.KEEPALIVE_CLIENT_COUNT_MAX=3;var mo=class extends Yi{constructor(t,e,r,s,i,o,a){super();let c=0,l=!1,f=[],u,h,p,A=[];this._sock=t,this._chanMgr=new eE(this),this._debug=i,this.noMoreSessions=!1,this.authenticated=!1;function y(N){}this.on("error",y);let b=i?(N,S,w)=>{i(`Debug output from client: ${JSON.stringify(w)}`)}:void 0,x=typeof a.keepaliveInterval=="number"&&isFinite(a.keepaliveInterval)&&a.keepaliveInterval>0?a.keepaliveInterval:typeof hn.KEEPALIVE_CLIENT_INTERVAL=="number"&&isFinite(hn.KEEPALIVE_CLIENT_INTERVAL)&&hn.KEEPALIVE_CLIENT_INTERVAL>0?hn.KEEPALIVE_CLIENT_INTERVAL:-1,B=typeof a.keepaliveCountMax=="number"&&isFinite(a.keepaliveCountMax)&&a.keepaliveCountMax>=0?a.keepaliveCountMax:typeof hn.KEEPALIVE_CLIENT_COUNT_MAX=="number"&&isFinite(hn.KEEPALIVE_CLIENT_COUNT_MAX)&&hn.KEEPALIVE_CLIENT_COUNT_MAX>=0?hn.KEEPALIVE_CLIENT_COUNT_MAX:-1,H=0;x!==-1&&B!==-1&&(this.once("ready",()=>{let N=()=>{clearInterval(h)};this.on("close",N).on("end",N),h=setInterval(()=>{if(++H>B){clearInterval(h);let S=new Error("Keepalive timeout");S.level="client-timeout",this.emit("error",S),this.end()}else C.ping()},x)}),p=()=>{h&&h.refresh(),H=0});let C=this._protocol=new GA({server:!0,hostKeys:e,ident:r,offer:s,onPacket:p,greeting:a.greeting,banner:a.banner,onWrite:N=>{uo(t)&&t.write(N)},onError:N=>{C._destruct||t.removeAllListeners("data"),this.emit("error",N);try{t.end()}catch{}},onHeader:N=>{this.removeListener("error",y);let S={ip:t.remoteAddress,family:t.remoteFamily,port:t.remotePort,header:N};if(!o.emit("connection",this,S)){C.disconnect(ti.BY_APPLICATION),t.end();return}N.greeting&&this.emit("greeting",N.greeting)},onHandshakeComplete:N=>{++c>1&&this.emit("rekey"),this.emit("handshake",N)},debug:i,messageHandlers:{DEBUG:b,DISCONNECT:(N,S,w)=>{if(S!==ti.BY_APPLICATION){w||(w=HA[S],w===void 0&&(w=`Unexpected disconnection reason: ${S}`));let v=new Error(w);v.code=S,this.emit("error",v)}t.end()},CHANNEL_OPEN:(N,S)=>{if(S.type==="session"&&this.noMoreSessions||!this.authenticated){let te=ei.ADMINISTRATIVELY_PROHIBITED;return C.channelOpenFail(S.sender,te)}let w=-1,v,k=!1,P,ne=()=>{k||(k=!0,v===void 0&&(w===-1?v=ei.RESOURCE_SHORTAGE:v=ei.CONNECT_FAILED),w!==-1&&this._chanMgr.remove(w),C.channelOpenFail(S.sender,v,""))},Y=()=>(w=this._chanMgr.add(),w===-1&&(v=ei.RESOURCE_SHORTAGE,i&&i("Automatic rejection of incoming channel open: no channels available")),w!==-1),G=S.data;switch(S.type){case"session":if(Xt(this,"session")&&Y()){P=()=>{if(k)return;k=!0;let te=new Tn(this,S,w);return this._chanMgr.update(w,te),C.channelOpenConfirm(S.sender,w,sr,or),te},this.emit("session",P,ne);return}break;case"direct-tcpip":if(Xt(this,"tcpip")&&Y()){P=()=>{if(k)return;k=!0;let te={type:void 0,incoming:{id:w,window:sr,packetSize:or,state:"open"},outgoing:{id:S.sender,window:S.window,packetSize:S.packetSize,state:"open"}},le=new ni(this,te,{server:!0});return this._chanMgr.update(w,le),C.channelOpenConfirm(S.sender,w,sr,or),le},this.emit("tcpip",P,ne,G);return}break;case"direct-streamlocal@openssh.com":if(Xt(this,"openssh.streamlocal")&&Y()){P=()=>{if(k)return;k=!0;let te={type:void 0,incoming:{id:w,window:sr,packetSize:or,state:"open"},outgoing:{id:S.sender,window:S.window,packetSize:S.packetSize,state:"open"}},le=new ni(this,te,{server:!0});return this._chanMgr.update(w,le),C.channelOpenConfirm(S.sender,w,sr,or),le},this.emit("openssh.streamlocal",P,ne,G);return}break;default:v=ei.UNKNOWN_CHANNEL_TYPE,i&&i(`Automatic rejection of unsupported incoming channel open type: ${S.type}`)}v===void 0&&(v=ei.ADMINISTRATIVELY_PROHIBITED,i&&i(`Automatic rejection of unexpected incoming channel open for: ${S.type}`)),ne()},CHANNEL_OPEN_CONFIRMATION:(N,S)=>{let w=this._chanMgr.get(S.recipient);if(typeof w!="function")return;let v={type:w.type,incoming:{id:S.recipient,window:sr,packetSize:or,state:"open"},outgoing:{id:S.sender,window:S.window,packetSize:S.packetSize,state:"open"}},k=new ni(this,v,{server:!0});this._chanMgr.update(S.recipient,k),w(void 0,k)},CHANNEL_OPEN_FAILURE:(N,S,w,v)=>{let k=this._chanMgr.get(S);if(typeof k!="function")return;tE(this,S,{reason:w,description:v},k)},CHANNEL_DATA:(N,S,w)=>{let v=this._chanMgr.get(S);if(!(typeof v!="object"||v===null)&&!(v.constructor===Tn&&(v=v._channel,!v))&&v.incoming.window!==0){if(v.incoming.window-=w.length,v.push(w)===!1){v._waitChanDrain=!0;return}v.incoming.window<=ZA&&JA(v)}},CHANNEL_EXTENDED_DATA:(N,S,w,v)=>{},CHANNEL_WINDOW_ADJUST:(N,S,w)=>{let v=this._chanMgr.get(S);typeof v!="object"||v===null||v.constructor===Tn&&(v=v._channel,!v)||(v.outgoing.window+=w,v._waitWindow&&(v._waitWindow=!1,v._chunk?v._write(v._chunk,null,v._chunkcb):v._chunkcb?v._chunkcb():v._chunkErr?v.stderr._write(v._chunkErr,null,v._chunkcbErr):v._chunkcbErr&&v._chunkcbErr()))},CHANNEL_SUCCESS:(N,S)=>{let w=this._chanMgr.get(S);typeof w!="object"||w===null||w.constructor===Tn&&(w=w._channel,!w)||w._callbacks.length&&w._callbacks.shift()(!1)},CHANNEL_FAILURE:(N,S)=>{let w=this._chanMgr.get(S);typeof w!="object"||w===null||w.constructor===Tn&&(w=w._channel,!w)||w._callbacks.length&&w._callbacks.shift()(!0)},CHANNEL_REQUEST:(N,S,w,v,k)=>{let P=this._chanMgr.get(S);if(typeof P!="object"||P===null)return;let ne=!1,Y,G;if(P.constructor!==Tn){v&&C.channelFailure(P.outgoing.id);return}if(v&&(w!=="shell"&&w!=="exec"&&w!=="subsystem"&&(Y=()=>{ne||P._ending||P._channel||(ne=!0,C.channelSuccess(P._chanInfo.outgoing.id))}),G=()=>{ne||P._ending||P._channel||(ne=!0,C.channelFailure(P._chanInfo.outgoing.id))}),P._ending){G&&G();return}switch(w){case"env":if(Xt(P,"env")){P.emit("env",Y,G,{key:k.name,val:k.value});return}break;case"pty-req":if(Xt(P,"pty")){P.emit("pty",Y,G,k);return}break;case"window-change":Xt(P,"window-change")?P.emit("window-change",Y,G,k):G&&G();break;case"x11-req":if(Xt(P,"x11")){P.emit("x11",Y,G,k);return}break;case"signal":if(Xt(P,"signal")){P.emit("signal",Y,G,{name:k});return}break;case"auth-agent-req@openssh.com":if(Xt(P,"auth-agent")){P.emit("auth-agent",Y,G);return}break;case"shell":if(Xt(P,"shell")){Y=()=>{if(ne||P._ending||P._channel)return;ne=!0,v&&C.channelSuccess(P._chanInfo.outgoing.id);let te=new ni(this,P._chanInfo,{server:!0});return te.subtype=P.subtype=w,P._channel=te,te},P.emit("shell",Y,G);return}break;case"exec":if(Xt(P,"exec")){Y=()=>{if(ne||P._ending||P._channel)return;ne=!0,v&&C.channelSuccess(P._chanInfo.outgoing.id);let te=new ni(this,P._chanInfo,{server:!0});return te.subtype=P.subtype=w,P._channel=te,te},P.emit("exec",Y,G,{command:k});return}break;case"subsystem":{let te=k==="sftp";if(Y=()=>{if(ne||P._ending||P._channel)return;ne=!0,v&&C.channelSuccess(P._chanInfo.outgoing.id);let le;return te?le=new jA(this,P._chanInfo,{server:!0,debug:i}):(le=new ni(this,P._chanInfo,{server:!0}),le.subtype=P.subtype=`${w}:${k}`),P._channel=le,le},k==="sftp"){if(Xt(P,"sftp")){P.emit("sftp",Y,G);return}te=!1}if(Xt(P,"subsystem")){P.emit("subsystem",Y,G,{name:k});return}break}}i&&i(`Automatic rejection of incoming channel request: ${w}`),G&&G()},CHANNEL_EOF:(N,S)=>{let w=this._chanMgr.get(S);typeof w!="object"||w===null||w.constructor===Tn&&(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:(N,S)=>{let w=this._chanMgr.get(S);typeof w!="object"||w===null||w.constructor===Tn&&(w._ending=!0,w.emit("close"),w=w._channel,!w)||nE(this,S,w)},SERVICE_REQUEST:(N,S)=>{if(c===0||l||this.authenticated||S!=="ssh-userauth"){C.disconnect(ti.SERVICE_NOT_AVAILABLE),t.end();return}l=!0,C.serviceAccept(S)},USERAUTH_REQUEST:(N,S,w,v,k)=>{if(c===0||this.authenticated||u&&(u.username!==S||u.service!==w)||v!=="password"&&v!=="publickey"&&v!=="hostbased"&&v!=="keyboard-interactive"&&v!=="none"||f.length===rE){C.disconnect(ti.PROTOCOL_ERROR),t.end();return}else if(w!=="ssh-connection"){C.disconnect(ti.SERVICE_NOT_AVAILABLE),t.end();return}let P;switch(v){case"keyboard-interactive":P=new ho(C,S,w,v,k,M);break;case"publickey":P=new wc(C,S,w,v,k,M);break;case"hostbased":P=new Ic(C,S,w,v,k,M);break;case"password":if(u&&u instanceof po&&u._changeCb){let ne=u._changeCb;u._changeCb=void 0,ne(k.newPassword);return}P=new po(C,S,w,v,k,M);break;case"none":P=new ar(C,S,w,v,M);break}if(u)if(u._initialResponse)u._multistep&&!u._finalResponse&&(u._cleanup&&u._cleanup(),u.emit("abort"));else return f.push(P);u=P,Xt(this,"authentication")?this.emit("authentication",u):u.reject()},USERAUTH_INFO_RESPONSE:(N,S)=>{u&&u instanceof ho&&u._onInfoResponse(S)},GLOBAL_REQUEST:(N,S,w,v)=>{let k={type:null,buf:null};function P(ne,Y){k.type=ne,k.buf=Y,Q()}if(w&&A.push(k),(S==="tcpip-forward"||S==="cancel-tcpip-forward"||S==="no-more-sessions@openssh.com"||S==="streamlocal-forward@openssh.com"||S==="cancel-streamlocal-forward@openssh.com")&&Xt(this,"request")&&this.authenticated){let ne,Y;if(w){let G=!1;ne=te=>{if(G)return;G=!0;let le;S==="tcpip-forward"&&v.bindPort===0&&typeof te=="number"&&(le=Buffer.allocUnsafe(4),XA(le,te,0)),P("SUCCESS",le)},Y=()=>{G||(G=!0,P("FAILURE"))}}if(S==="no-more-sessions@openssh.com"){this.noMoreSessions=!0,ne&&ne();return}this.emit("request",ne,Y,S,v)}else w&&P("FAILURE")}}});t.pause(),zA.then(()=>{C.start(),t.on("data",N=>{try{C.parse(N,0,N.length)}catch(S){this.emit("error",S);try{uo(t)&&t.end()}catch{}}}),t.resume()}).catch(N=>{this.emit("error",N);try{uo(t)&&t.end()}catch{}}),t.on("error",N=>{N.level="socket",this.emit("error",N)}).once("end",()=>{i&&i("Socket ended"),C.cleanup(),this.emit("end")}).once("close",()=>{i&&i("Socket closed"),C.cleanup(),this.emit("close");let N=new Error("No response from server");this._chanMgr.cleanup(N)});let M=(N,S,w,v)=>{u===N&&!this.authenticated&&(S?(u=void 0,this.authenticated=!0,C.authSuccess(),f=[],this.emit("ready")):(C.authFailure(w,v),f.length&&(u=f.pop(),Xt(this,"authentication")?this.emit("authentication",u):u.reject())))};function Q(){for(;A.length>0&&A[0].type;){let N=A.shift();N.type==="SUCCESS"&&C.requestSuccess(N.buf),N.type==="FAILURE"&&C.requestFailure()}}}end(){return this._sock&&uo(this._sock)&&(this._protocol.disconnect(ti.BY_APPLICATION),this._sock.end()),this}x11(t,e,r){return xc(this,"x11",{originAddr:t,originPort:e},r),this}forwardOut(t,e,r,s,i){return xc(this,"forwarded-tcpip",{boundAddr:t,boundPort:e,remoteAddr:r,remotePort:s},i),this}openssh_forwardOutStreamLocal(t,e){return xc(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 xc(n,t,e,r){let s=sr,i=or;typeof e=="function"&&(r=e,e={});let o=(c,l)=>{r(c,l)};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 iE(n,t){return n-t}Cc.exports=hn;Cc.exports.IncomingClient=mo});var Th=lt((Kx,Ph)=>{"use strict";var{createCipheriv:sE,generateKeyPair:oE,generateKeyPairSync:aE,getCurves:cE,randomBytes:Nh}=require("crypto"),{Ber:wt}=Si(),lE=Ko().pbkdf,{CIPHER_INFO:fE}=Zn(),uE=16,dE=16,hE=cE(),pE=new Map(Object.entries(fE));function Bh(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(!hE.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 mE(n,t,e){switch(n){case"rsa":{let r=new wt.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()!==wt.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 wt.Reader(r.readString(wt.OctetString,!0)),r.readSequence(),r.readInt()!==0)throw new Error("Unsupported version in RSA private key");let s=r.readString(wt.Integer,!0),i=r.readString(wt.Integer,!0),o=r.readString(wt.Integer,!0),a=r.readString(wt.Integer,!0),c=r.readString(wt.Integer,!0);r.readString(wt.Integer,!0),r.readString(wt.Integer,!0);let l=r.readString(wt.Integer,!0),f=Buffer.from("ssh-rsa"),u=Buffer.allocUnsafe(4+f.length+4+s.length+4+i.length+4+o.length+4+l.length+4+a.length+4+c.length),h=0;u.writeUInt32BE(f.length,h+=0),u.set(f,h+=4),u.writeUInt32BE(s.length,h+=f.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(l.length,h+=o.length),u.set(l,h+=4),u.writeUInt32BE(a.length,h+=l.length),u.set(a,h+=4),u.writeUInt32BE(c.length,h+=a.length),u.set(c,h+=4);let p=Buffer.allocUnsafe(4+f.length+4+i.length+4+s.length);return h=0,p.writeUInt32BE(f.length,h+=0),p.set(f,h+=4),p.writeUInt32BE(i.length,h+=f.length),p.set(i,h+=4),p.writeUInt32BE(s.length,h+=i.length),p.set(s,h+=4),{sshName:f.toString(),priv:u,pub:p}}case"ec":{let r=new wt.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(wt.BitString,!0);{let h=0;for(;h<s.length&&s[h]===0;++h);h>0&&(s=s.slice(h))}if(r=new wt.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 wt.Reader(r.readString(wt.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(wt.OctetString,!0)]),c=Buffer.from(`ecdsa-sha2-${o}`);o=Buffer.from(o);let l=Buffer.allocUnsafe(4+c.length+4+o.length+4+s.length+4+a.length),f=0;l.writeUInt32BE(c.length,f+=0),l.set(c,f+=4),l.writeUInt32BE(o.length,f+=c.length),l.set(o,f+=4),l.writeUInt32BE(s.length,f+=o.length),l.set(s,f+=4),l.writeUInt32BE(a.length,f+=s.length),l.set(a,f+=4);let u=Buffer.allocUnsafe(4+c.length+4+o.length+4+s.length);return f=0,u.writeUInt32BE(c.length,f+=0),u.set(c,f+=4),u.writeUInt32BE(o.length,f+=c.length),u.set(o,f+=4),u.writeUInt32BE(s.length,f+=o.length),u.set(s,f+=4),{sshName:c.toString(),priv:l,pub:u}}case"ed25519":{let r=new wt.Reader(t);if(r.readSequence(),r.readSequence(),r.readOID()!=="1.3.101.112")throw new Error("Bad ED25519 public OID");let s=r.readString(wt.BitString,!0);{let f=0;for(;f<s.length&&s[f]===0;++f);f>0&&(s=s.slice(f))}if(r=new wt.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 wt.Reader(r.readString(wt.OctetString,!0));let i=r.readString(wt.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 l=Buffer.allocUnsafe(4+o.length+4+s.length);return c=0,l.writeUInt32BE(o.length,c+=0),l.set(o,c+=4),l.writeUInt32BE(s.length,c+=o.length),l.set(s,c+=4),{sshName:o.toString(),priv:a,pub:l}}}}function Rh(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=pE.get(r.cipher);if(c===void 0)throw new Error("Invalid cipher name");if(s==="new"){let l=dE;if(r.rounds!==void 0){if(!Number.isInteger(r.rounds))throw new TypeError("rounds must be an integer");r.rounds>0&&(l=r.rounds)}let f=Buffer.allocUnsafe(c.keyLen+c.ivLen),u=Nh(uE);if(lE(a,a.length,u,u.length,f,f.length,l)!==0)return new Error("Failed to generate information to encrypt key");let p=Buffer.allocUnsafe(4+u.length+4);{let A=0;p.writeUInt32BE(u.length,A+=0),p.set(u,A+=4),p.writeUInt32BE(l,A+=u.length)}i={cipher:c,cipherName:r.cipher,kdfName:"bcrypt",kdfOptions:p,key:f.slice(0,c.keyLen),iv:f.slice(c.keyLen)}}}switch(s){case"new":{let a=`-----BEGIN OPENSSH PRIVATE KEY-----
16
- `,c,l=Buffer.from(i?i.cipherName:"none"),f=Buffer.from(i?i.kdfName:"none"),u=i?i.kdfOptions:Buffer.alloc(0),h=i?i.cipher.blockLen:8,p=mE(n,t,e),A=Nh(4),y=Buffer.from(o),b=8+p.priv.length+4+y.length,x=[];for(let Q=1;(b+x.length)%h;++Q)x.push(Q&255);x=Buffer.from(x);let B=Buffer.allocUnsafe(b+x.length),H;{let Q=0;B.set(A,Q+=0),B.set(A,Q+=4),B.set(p.priv,Q+=4),B.writeUInt32BE(y.length,Q+=p.priv.length),B.set(y,Q+=4),B.set(x,Q+=y.length)}if(i){let Q={authTagLength:i.cipher.authLen},N=sE(i.cipher.sslName,i.key,i.iv,Q);N.setAutoPadding(!1),B=Buffer.concat([N.update(B),N.final()]),i.cipher.authLen>0?H=N.getAuthTag():H=Buffer.alloc(0),i.key.fill(0),i.iv.fill(0)}else H=Buffer.alloc(0);let C=Buffer.from("openssh-key-v1\0"),M=Buffer.allocUnsafe(C.length+4+l.length+4+f.length+4+u.length+4+4+p.pub.length+4+B.length+H.length);{let Q=0;M.set(C,Q+=0),M.writeUInt32BE(l.length,Q+=C.length),M.set(l,Q+=4),M.writeUInt32BE(f.length,Q+=l.length),M.set(f,Q+=4),M.writeUInt32BE(u.length,Q+=f.length),M.set(u,Q+=4),M.writeUInt32BE(1,Q+=u.length),M.writeUInt32BE(p.pub.length,Q+=4),M.set(p.pub,Q+=4),M.writeUInt32BE(B.length,Q+=p.pub.length),M.set(B,Q+=4),M.set(H,Q+=B.length)}{let Q=M.base64Slice(0,M.length),N=Q.replace(/.{64}/g,`$&
17
- `);Q.length&63&&(N+=`
18
- `),a+=N}{let Q=p.pub.base64Slice(0,p.pub.length);c=`${p.sshName} ${Q}${o?` ${o}`:""}`}return a+=`-----END OPENSSH PRIVATE KEY-----
19
- `,{private:a,public:c}}default:throw new Error("Invalid output key format")}}function gE(){}Ph.exports={generateKeyPair:(n,t,e)=>{typeof t=="function"&&(e=t,t=void 0),typeof e!="function"&&(e=gE);let r=Bh(n,t);oE(...r,(s,i,o)=>{if(s)return e(s);let a;try{a=Rh(r[0],i,o,t)}catch(c){return e(c)}e(null,a)})},generateKeyPairSync:(n,t)=>{let e=Bh(n,t),{publicKey:r,privateKey:s}=aE(...e);return Rh(e[0],r,s,t)}}});var vc=lt((Vx,Oh)=>{"use strict";var{AgentProtocol:AE,BaseAgent:EE,createAgent:yE,CygwinAgent:_E,OpenSSHAgent:SE,PageantAgent:bE}=Ta(),{SSHTTPAgent:xE,SSHTTPSAgent:wE}=Ch(),{parseKey:IE}=nr(),{flagsToString:CE,OPEN_MODE:vE,STATUS_CODE:kE,stringToFlags:NE}=Fi();Oh.exports={AgentProtocol:AE,BaseAgent:EE,createAgent:yE,Client:_c(),CygwinAgent:_E,HTTPAgent:xE,HTTPSAgent:wE,OpenSSHAgent:SE,PageantAgent:bE,Server:kh(),utils:{parseKey:IE,...Th(),sftp:{flagsToString:CE,OPEN_MODE:vE,STATUS_CODE:kE,stringToFlags:NE}}}});function zc(n){return n==="1"||n==="true"}function Yc(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}function Np(){return zc(process.env.DEV_MODE)||zc(process.env.RENDER_PERF)}function mn(n){let t=Np();if(!t)return{enabled:t,mark:()=>{},done:()=>{}};let e=Yc(),r=i=>{let o=Yc()-e;console.log(`[perf][${n}] ${i}: ${o.toFixed(1)}ms`)};return{enabled:t,mark:r,done:(i="done")=>{r(i)}}}var ry=mn("HoneyPot");var Gc={name:"adduser",description:"Add a new user",category:"users",params:["<username>"],run:({authUser:n,shell:t,args:e})=>{if(n!=="root")return{stderr:`adduser: permission denied
20
- `,exitCode:1};let r=e[0];if(!r)return{stderr:`Usage: adduser <username>
21
- `,exitCode:1};if(t.users.listUsers().includes(r))return{stderr:`adduser: user '${r}' already exists
22
- `,exitCode:1};let s="",i="new";return{sudoChallenge:{username:r,targetUser:r,commandLine:null,loginShell:!1,prompt:"New password: ",mode:"passwd",onPassword:async(a,c)=>i==="new"?a.length<1?{result:{stderr:`adduser: password cannot be empty
23
- `,exitCode:1}}:(s=a,i="retype",{result:null,nextPrompt:"Retype new password: "}):a!==s?{result:{stderr:`adduser: passwords do not match \u2014 user not created
24
- `,exitCode:1}}:(await c.users.addUser(r,s),{result:{stdout:`${[`Adding user '${r}' ...`,`Adding new group '${r}' (1001) ...`,`Adding new user '${r}' (1001) with group '${r}' ...`,`Creating home directory '/home/${r}' ...`,`passwd: password set for '${r}'`,"adduser: done."].join(`
25
- `)}
26
- `,exitCode:0}})},exitCode:0}}};function jc(n){return Array.isArray(n)?n:[n]}function as(n,t){if(n===t)return{matched:!0,inlineValue:null};let e=`${t}=`;return n.startsWith(e)?{matched:!0,inlineValue:n.slice(e.length)}:t.length===2&&t.startsWith("-")&&!t.startsWith("--")&&n.startsWith(t)&&n.length>t.length?{matched:!0,inlineValue:n.slice(t.length)}:{matched:!1,inlineValue:null}}function Bp(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 l of e){let{matched:f}=as(a,l);if(f){c=!0;break}}if(!c){for(let l of r){let f=as(a,l);if(f.matched){c=!0,f.inlineValue===null&&o+1<n.length&&(o+=1);break}}c||s.push(a)}}return s}function se(n,t){let e=jc(t);for(let r of n)for(let s of e)if(as(r,s).matched)return!0;return!1}function Jt(n,t){let e=jc(t);for(let r=0;r<n.length;r+=1){let s=n[r];for(let i of e){let o=as(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 Bp(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 l=n[c];if(a){s.push(l);continue}if(l==="--"){a=!0;continue}if(i.has(l)){e.add(l);continue}if(o.has(l)){let u=n[c+1];u&&!u.startsWith("-")?(r.set(l,u),c+=1):r.set(l,"");continue}let f=Array.from(o).find(u=>l.startsWith(`${u}=`));if(f){r.set(f,l.slice(f.length+1));continue}s.push(l)}return{flags:e,flagsWithValues:r,positionals:s}}var Xc={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(`
27
- `)||"",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(`
28
- `)||void 0,exitCode:0}}},Jc={name:"unalias",description:"Remove alias definitions",category:"shell",params:["<name...> | -a"],run:({args:n,env:t})=>{if(!t)return{exitCode:0};if(se(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 _n=Wt(require("node:path"),1),Rp=["/.virtual-env-js/.auth","/etc/htpasswd"];function de(n,t){return!t||t.trim()===""?n:t.startsWith("~")?_n.posix.normalize(`/home/${t.slice(1)}`):t.startsWith("/")?_n.posix.normalize(t):_n.posix.normalize(_n.posix.join(n,t))}function Pp(n){let t=n.startsWith("/")?_n.posix.normalize(n):_n.posix.normalize(`/${n}`);return Rp.some(e=>t===e||t.startsWith(`${e}/`))}function $e(n,t,e){if(n!=="root"&&Pp(t))throw new Error(`${e}: permission denied: ${t}`)}function Zc(n){let e=(n.split("?")[0]?.split("#")[0]??n).split("/").filter(Boolean).pop();return e&&e.length>0?e:"index.html"}function Tp(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 el(n,t,e){let r=de(t,e);if(n.exists(r))return r;let s=_n.posix.dirname(r),i=_n.posix.basename(r),o=n.list(s),a=o.filter(l=>l.toLowerCase()===i.toLowerCase());if(a.length===1)return _n.posix.join(s,a[0]);let c=o.filter(l=>Tp(l.toLowerCase(),i.toLowerCase())<=1);return c.length===1?_n.posix.join(s,c[0]):r}function Br(n){return n.packageManager}var tl={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=Br(t);if(!r)return{stderr:"apt: package manager not initialised",exitCode:1};let s=n[0]?.toLowerCase(),i=n.slice(1),o=se(i,["-q","--quiet","-qq"]),a=se(i,["--purge"]),c=i.filter(f=>!f.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)
29
- 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:f,exitCode:u}=r.install(c,{quiet:o});return{stdout:f||void 0,exitCode:u}}case"remove":case"purge":{if(c.length===0)return{stderr:"apt: no packages specified",exitCode:1};let{output:f,exitCode:u}=r.remove(c,{purge:s==="purge"||a,quiet:o});return{stdout:f||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(`
30
- `),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(`
31
- `),exitCode:0};case"search":{let f=c[0];if(!f)return{stderr:"apt: search requires a term",exitCode:1};let u=r.search(f);return u.length===0?{stdout:`Sorting... Done
32
- Full Text Search... Done
33
- (no results)`,exitCode:0}:{stdout:`Sorting... Done
34
- Full Text Search... Done
35
- ${u.map(p=>`${p.name}/${p.section??"misc"} ${p.version} amd64
36
- ${p.shortDesc??p.description}`).join(`
37
- `)}`,exitCode:0}}case"show":{let f=c[0];if(!f)return{stderr:"apt: show requires a package name",exitCode:1};let u=r.show(f);return u?{stdout:u,exitCode:0}:{stderr:`N: Unable to locate package ${f}`,exitCode:100}}case"list":{if(se(i,["--installed"])){let p=r.listInstalled();return p.length===0?{stdout:`Listing... Done
38
- (no packages installed)`,exitCode:0}:{stdout:`Listing... Done
39
- ${p.map(y=>`${y.name}/${y.section} ${y.version} ${y.architecture} [installed]`).join(`
40
- `)}`,exitCode:0}}return{stdout:`Listing... Done
41
- ${r.listAvailable().map(p=>`${p.name}/${p.section??"misc"} ${p.version} amd64`).join(`
42
- `)}`,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(`
43
- `),exitCode:0}}}},nl={name:"apt-cache",description:"Query the package cache",category:"package",params:["<search|show|policy> [pkg]"],run:({args:n,shell:t})=>{let e=Br(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(`
44
- `)||"(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(`
45
- `),exitCode:0}}default:return{stderr:`apt-cache: unknown command '${r??""}'`,exitCode:1}}}};var rl={name:"awk",description:"Pattern scanning and processing language",category:"text",params:["[-F <sep>] '<program>' [file]"],run:({authUser:n,args:t,stdin:e,cwd:r,shell:s})=>{let i=Jt(t,["-F"])??" ",o=t.filter(C=>!C.startsWith("-")&&C!==i),a=o[0],c=o[1];if(!a)return{stderr:"awk: no program",exitCode:1};let l=e??"";if(c){let C=de(r,c);try{$e(n,C,"awk"),l=s.vfs.readFile(C)}catch{return{stderr:`awk: ${c}: No such file or directory`,exitCode:1}}}let f=l.split(`
46
- `);f[f.length-1]===""&&f.pop();let u=[],h=a.trim();if(!h.startsWith("{")&&!h.includes("{"))u.push({pattern:h,action:"print $0"});else{let C=/([^{]*)\{([^}]*)\}/g,M=C.exec(h);for(;M!==null;)u.push({pattern:M[1].trim(),action:M[2].trim()}),M=C.exec(h);u.length===0&&u.push({pattern:"",action:h.replace(/[{}]/g,"").trim()})}let p=[],A=u.find(C=>C.pattern==="BEGIN"),y=u.find(C=>C.pattern==="END"),b=u.filter(C=>C.pattern!=="BEGIN"&&C.pattern!=="END");function x(C){return i===" "?C.trim().split(/\s+/).filter(Boolean):C.split(i)}function B(C,M,Q){let N=x(M),S=N.length,w=k=>{if(k=k.trim(),k==="NR")return String(Q);if(k==="NF")return String(S);if(k==="$0")return M;if(k==="$NF")return N[S-1]??"";if(/^\$\d+$/.test(k))return N[parseInt(k.slice(1),10)-1]??"";let P=k.replace(/\bNR\b/g,String(Q)).replace(/\bNF\b/g,String(S));if(/^[\d\s+\-*/()]+$/.test(P))try{return String(Function(`"use strict"; return (${P});`)())}catch{}return k.replace(/"/g,"")},v=C.split(";").map(k=>k.trim()).filter(Boolean);for(let k of v)if(k==="print"||k==="print $0")p.push(M);else if(k.startsWith("print ")){let P=k.slice(6).split(/\s*,\s*/);p.push(P.map(w).join(" "))}}function H(C,M,Q){if(!C||C==="1")return!0;let N=C.match(/^NR\s*([=!<>]=?|==)\s*(\d+)$/);if(N){let v=N[1],k=parseInt(N[2],10);switch(v){case"==":return Q===k;case"!=":return Q!==k;case">":return Q>k;case">=":return Q>=k;case"<":return Q<k;case"<=":return Q<=k}}let S=C.match(/^NR%(\d+)==(\d+)$/);if(S)return Q%parseInt(S[1],10)===parseInt(S[2],10);if(C.startsWith("/")&&C.endsWith("/"))try{return new RegExp(C.slice(1,-1)).test(M)}catch{return!1}let w=C.match(/^\$(\d+)~\/(.*)\/$/);if(w){let k=x(M)[parseInt(w[1],10)-1]??"";try{return new RegExp(w[2]).test(k)}catch{return!1}}return!1}A&&B(A.action,"",0);for(let C=1;C<=f.length;C++){let M=f[C-1];for(let Q of b)H(Q.pattern,M,C)&&B(Q.action,M,C)}return y&&B(y.action,"",f.length+1),{stdout:p.join(`
47
- `)+(p.length>0?`
48
- `:""),exitCode:0}}};var il={name:"base64",description:"Encode/decode base64",category:"text",params:["[-d] [file]"],run:({args:n,stdin:t})=>{let e=se(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 sl={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=se(r,["-n","--number"]),o=se(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 p=el(t.vfs,e,h);$e(n,p,"cat"),c.push(t.vfs.readFile(p))}let l=c.join("");if(!i&&!o)return{stdout:l,exitCode:0};let f=1;return{stdout:l.split(`
49
- `).map(h=>o&&h.trim()===""?h:`${String(f++).padStart(6)} ${h}`).join(`
50
- `),exitCode:0}}};var ol={name:"cd",description:"Change directory",category:"navigation",params:["[path]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=de(e,r[0]??"~");return $e(n,s,"cd"),t.vfs.stat(s).type!=="directory"?{stderr:`cd: not a directory: ${s}`,exitCode:1}:{nextCwd:s,exitCode:0}}};function Op(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,l=""]=o,f=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 f)for(let p of l.split("")){let A=u[h]?.[p];if(A!==void 0){if(c==="+")s|=A;else if(c==="-")s&=~A;else if(c==="="){let y=Object.values(u[h]??{}).reduce((b,x)=>b|x,0);s=s&~y|A}}}}return s}var al={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=de(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 l=t.vfs.stat(o).mode,f=Op(l,s);if(f===null)return{stderr:`chmod: invalid mode: ${s}`,exitCode:1};a=f}return t.vfs.chmod(o,a),{exitCode:0}}catch(a){return{stderr:`chmod: ${a instanceof Error?a.message:String(a)}`,exitCode:1}}}};var cl={name:"clear",description:"Clear the terminal screen",category:"shell",params:[],run:()=>({clearScreen:!0,stdout:"",exitCode:0})};var ll={name:"cp",description:"Copy files or directories",category:"files",params:["[-r] <source> <dest>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=se(r,["-r","-R","--recursive"]),i=r.filter(f=>!f.startsWith("-")),[o,a]=i;if(!o||!a)return{stderr:"cp: missing operand",exitCode:1};let c=de(e,o),l=de(e,a);try{if($e(n,c,"cp"),$e(n,l,"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=(p,A)=>{t.vfs.mkdir(A,493);for(let y of t.vfs.list(p)){let b=`${p}/${y}`,x=`${A}/${y}`;if(t.vfs.stat(b).type==="directory")u(b,x);else{let H=t.vfs.readFileRaw(b);t.writeFileAsUser(n,x,H)}}},h=t.vfs.exists(l)&&t.vfs.stat(l).type==="directory"?`${l}/${o.split("/").pop()}`:l;u(c,h)}else{let u=t.vfs.exists(l)&&t.vfs.stat(l).type==="directory"?`${l}/${o.split("/").pop()}`:l,h=t.vfs.readFileRaw(c);t.writeFileAsUser(n,u,h)}return{exitCode:0}}catch(f){return{stderr:`cp: ${f instanceof Error?f.message:String(f)}`,exitCode:1}}}};var fl={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(se(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(`
51
- `),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(),l=s.get("-d")??s.get("--data")??null,f=s.get("-H")??s.get("--header")??null,u=se(e,["-s","--silent"]),h=se(e,["-I","--head"]),p=se(e,["-L","--location"]),A=se(e,["-v","--verbose"]),y={"User-Agent":"curl/7.88.1"};if(f){let M=f.indexOf(":");M!==-1&&(y[f.slice(0,M).trim()]=f.slice(M+1).trim())}let b=l&&c==="GET"?"POST":c,x={method:b,headers:y,redirect:p?"follow":"manual"};l&&(y["Content-Type"]??="application/x-www-form-urlencoded",x.body=l);let B=[];A&&(B.push(`* Trying ${o}...`,"* Connected"),B.push(`> ${b} / HTTP/1.1`,`> Host: ${new URL(o).host}`));let H;try{let M=o.startsWith("http://")||o.startsWith("https://")?o:`http://${o}`;H=await fetch(M,x)}catch(M){return{stderr:`curl: (6) Could not resolve host: ${M instanceof Error?M.message:String(M)}`,exitCode:6}}if(A&&B.push(`< HTTP/1.1 ${H.status} ${H.statusText}`),h){let M=[`HTTP/1.1 ${H.status} ${H.statusText}`];for(let[Q,N]of H.headers.entries())M.push(`${Q}: ${N}`);return{stdout:`${M.join(`\r
52
- `)}\r
53
- `,exitCode:0}}let C;try{C=await H.text()}catch{return{stderr:"curl: failed to read response body",exitCode:1}}if(a){let M=de(t,a);return $e(n,M,"curl"),r.writeFileAsUser(n,M,C),u||B.push(` % Total % Received
54
- 100 ${C.length} 100 ${C.length}`),{stderr:B.join(`
55
- `)||void 0,exitCode:H.ok?0:22}}return{stdout:C,stderr:B.length>0?B.join(`
56
- `):void 0,exitCode:H.ok?0:22}}};var ul={name:"cut",description:"Remove sections from lines",category:"text",params:["-d <delim> -f <fields> [file]"],run:({args:n,stdin:t})=>{let e=Jt(n,["-d"])??" ",s=(Jt(n,["-f"])??"1").split(",").map(a=>{let[c,l]=a.split("-").map(Number);return l!==void 0?{from:(c??1)-1,to:l-1}:{from:(c??1)-1,to:(c??1)-1}});return{stdout:(t??"").split(`
57
- `).map(a=>{let c=a.split(e),l=[];for(let f of s)for(let u=f.from;u<=Math.min(f.to,c.length-1);u++)l.push(c[u]??"");return l.join(e)}).join(`
58
- `),exitCode:0}}};var dl={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 hl={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=se(n,["-i"]),r=se(n,["-r"]),s=se(n,["-x"]);if(n.filter(a=>!a.startsWith("-")).length===0)return{stdout:Object.entries(t.vars).map(([c,l])=>`declare -- ${c}="${l}"`).join(`
59
- `),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 l=a.slice(0,c),f=a.slice(c+1);if(e){let u=parseInt(f,10);f=Number.isNaN(u)?"0":String(u)}t.vars[l]=f}}return{exitCode:0}}};var pl={name:"deluser",description:"Delete a user",category:"users",params:["[-f] <username>"],run:async({authUser:n,args:t,shell:e})=>{if(n!=="root")return{stderr:`deluser: permission denied
60
- `,exitCode:1};let r=t.includes("-f")||t.includes("--force")||t.includes("-y"),s=t.find(o=>!o.startsWith("-"));if(!s)return{stderr:`Usage: deluser [-f] <username>
61
- `,exitCode:1};if(!e.users.listUsers().includes(s))return{stderr:`deluser: user '${s}' does not exist
62
- `,exitCode:1};if(s==="root")return{stderr:`deluser: cannot remove the root account
63
- `,exitCode:1};if(r)return await e.users.deleteUser(s),{stdout:`Removing user '${s}' ...
64
- deluser: done.
65
- `,exitCode:0};let i=async(o,a)=>o.trim()!==s?{result:{stderr:`deluser: confirmation did not match \u2014 user not deleted
66
- `,exitCode:1}}:(await a.users.deleteUser(s),{result:{stdout:`Removing user '${s}' ...
67
- deluser: done.
68
- `,exitCode:0}});return{sudoChallenge:{username:s,targetUser:s,commandLine:null,loginShell:!1,prompt:`Warning: deleting user '${s}'.
69
- Type the username to confirm: `,mode:"confirm",onPassword:i},exitCode:0}}};var ml={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}
70
- ${a}`,exitCode:0}}};var gl={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=de(t,r),o=de(t,s),a,c;try{a=n.vfs.readFile(i).split(`
71
- `)}catch{return{stderr:`diff: ${r}: No such file or directory`,exitCode:2}}try{c=n.vfs.readFile(o).split(`
72
- `)}catch{return{stderr:`diff: ${s}: No such file or directory`,exitCode:2}}let l=[],f=Math.max(a.length,c.length);for(let u=0;u<f;u++){let h=a[u],p=c[u];h!==p&&(h!==void 0&&l.push(`< ${h}`),p!==void 0&&l.push(`> ${p}`))}return{stdout:l.join(`
73
- `),exitCode:l.length>0?1:0}}};var Al={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=Br(e);if(!r)return{stderr:"dpkg: package manager not initialised",exitCode:1};let s=se(n,["-l","--list"]),i=se(n,["-s","--status"]),o=se(n,["-L","--listfiles"]),a=se(n,["-r","--remove"]),c=se(n,["-P","--purge"]),{positionals:l}=Zt(n,{flags:["-l","--list","-s","--status","-L","--listfiles","-r","--remove","-P","--purge"]});if(s){let f=r.listInstalled();if(f.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(`
74
- `),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=f.map(p=>{let A=p.name.padEnd(14).slice(0,14),y=p.version.padEnd(15).slice(0,15),b=p.architecture.padEnd(12).slice(0,12),x=(p.description||"").slice(0,40);return`ii ${A} ${y} ${b} ${x}`});return{stdout:[...u,...h].join(`
75
- `),exitCode:0}}if(i){let f=l[0];if(!f)return{stderr:"dpkg: -s needs a package name",exitCode:1};let u=r.show(f);return u?{stdout:u,exitCode:0}:{stderr:`dpkg-query: package '${f}' is not installed and no information is available`,exitCode:1}}if(o){let f=l[0];if(!f)return{stderr:"dpkg: -L needs a package name",exitCode:1};let u=r.listInstalled().find(h=>h.name===f);return u?u.files.length===0?{stdout:"/.keep",exitCode:0}:{stdout:u.files.join(`
76
- `),exitCode:0}:{stderr:`dpkg-query: package '${f}' is not installed`,exitCode:1}}if(a||c){if(t!=="root")return{stderr:"dpkg: error: requested operation requires superuser privilege",exitCode:2};if(l.length===0)return{stderr:"dpkg: error: need an action option",exitCode:2};let{output:f,exitCode:u}=r.remove(l,{purge:c});return{stdout:f||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(`
77
- `),exitCode:0}}},El={name:"dpkg-query",description:"Show information about installed packages",category:"package",params:["-W [pkg] | -l [pattern]"],run:({args:n,shell:t})=>{let e=Br(t);if(!e)return{stderr:"dpkg-query: package manager not initialised",exitCode:1};let r=se(n,["-l"]),s=se(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(f=>f.name.includes(a)):o;return s?{stdout:c.map(f=>`${f.name} ${f.version}`).join(`
78
- `),exitCode:0}:{stdout:c.map(f=>{let u=f.name.padEnd(14).slice(0,14),h=f.version.padEnd(15).slice(0,15);return`ii ${u} ${h} amd64 ${(f.description||"").slice(0,40)}`}).join(`
79
- `)||"(no packages match)",exitCode:0}}return{stderr:"dpkg-query: need a flag (-l, -W)",exitCode:1}}};var yl={name:"du",description:"Estimate file space usage",category:"system",params:["[-h] [-s] [path]"],run:({shell:n,cwd:t,args:e})=>{let r=se(e,["-h"]),s=se(e,["-s"]),i=e.find(f=>!f.startsWith("-"))??".",o=de(t,i),a=f=>r?`${(f/1024).toFixed(1)}K`:String(Math.ceil(f/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=[],l=(f,u)=>{let h=0;for(let p of n.vfs.list(f)){let A=`${f}/${p}`,y=`${u}/${p}`,b=n.vfs.stat(A);b.type==="directory"?h+=l(A,y):(h+=b.size,s||c.push(`${a(b.size)} ${y}`))}return c.push(`${a(h)} ${u}`),h};return l(o,i),{stdout:c.join(`
80
- `),exitCode:0}}};function Lp(n,t){let e=[],r=0;for(;r<n.length;){let s=n[r];if(/\s/.test(s)){r++;continue}if(s==="+"){e.push({type:"plus"}),r++;continue}if(s==="-"){e.push({type:"minus"}),r++;continue}if(s==="*"){if(n[r+1]==="*"){e.push({type:"pow"}),r+=2;continue}e.push({type:"mul"}),r++;continue}if(s==="/"){e.push({type:"div"}),r++;continue}if(s==="%"){e.push({type:"mod"}),r++;continue}if(s==="("){e.push({type:"lparen"}),r++;continue}if(s===")"){e.push({type:"rparen"}),r++;continue}if(/\d/.test(s)){let i=r+1;for(;i<n.length&&/\d/.test(n[i]);)i++;e.push({type:"number",value:Number(n.slice(r,i))}),r=i;continue}if(/[A-Za-z_]/.test(s)){let i=r+1;for(;i<n.length&&/[A-Za-z0-9_]/.test(n[i]);)i++;let o=n.slice(r,i),a=t[o],c=a===void 0||a===""?0:Number(a);e.push({type:"number",value:Number.isFinite(c)?c:0}),r=i;continue}return[]}return e}function wo(n,t){let e=n.trim();if(e.length===0||e.length>1024)return NaN;let r=Lp(e,t);if(r.length===0)return NaN;let s=0,i=()=>r[s],o=()=>r[s++],a=()=>{let p=o();if(!p)return NaN;if(p.type==="number")return p.value;if(p.type==="lparen"){let A=u();return r[s]?.type!=="rparen"?NaN:(s++,A)}return NaN},c=()=>{let p=i();return p?.type==="plus"?(o(),c()):p?.type==="minus"?(o(),-c()):a()},l=()=>{let p=c();for(;i()?.type==="pow";){o();let A=c();p=p**A}return p},f=()=>{let p=l();for(;;){let A=i();if(A?.type==="mul"){o(),p*=l();continue}if(A?.type==="div"){o();let y=l();p=y===0?NaN:p/y;continue}if(A?.type==="mod"){o();let y=l();p=y===0?NaN:p%y;continue}return p}},u=()=>{let p=f();for(;;){let A=i();if(A?.type==="plus"){o(),p+=f();continue}if(A?.type==="minus"){o(),p-=f();continue}return p}},h=u();return!Number.isFinite(h)||s!==r.length?NaN:Math.trunc(h)}function Dp(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 ls(n){function r(s,i){if(i>8)return[s];let o=0,a=-1;for(let c=0;c<s.length;c++){let l=s[c];if(l==="{"&&s[c-1]!=="$")o===0&&(a=c),o++;else if(l==="}"&&(o--,o===0&&a!==-1)){let f=s.slice(0,a),u=s.slice(a+1,c),h=s.slice(c+1),p=u.match(/^(-?\d+)\.\.(-?\d+)(?:\.\.-?(\d+))?$/)||u.match(/^([a-z])\.\.([a-z])$/);if(p){let x=[];if(/\d/.test(p[1])){let C=parseInt(p[1],10),M=parseInt(p[2],10),Q=p[3]?parseInt(p[3],10):1,N=C<=M?Q:-Q;for(let S=C;C<=M?S<=M:S>=M;S+=N)x.push(String(S))}else{let C=p[1].charCodeAt(0),M=p[2].charCodeAt(0),Q=C<=M?1:-1;for(let N=C;C<=M?N<=M:N>=M;N+=Q)x.push(String.fromCharCode(N))}let B=x.map(C=>`${f}${C}${h}`),H=[];for(let C of B)if(H.push(...r(C,i+1)),H.length>256)return[s];return H}let A=[],y="",b=0;for(let x of u)x==="{"?(b++,y+=x):x==="}"?(b--,y+=x):x===","&&b===0?(A.push(y),y=""):y+=x;if(A.push(y),A.length>1){let x=[];for(let B of A)if(x.push(...r(`${f}${B}${h}`,i+1)),x.length>256)return[s];return x}break}}return[s]}return r(n,0)}function Mp(n,t){let e="",r=0;for(;r<n.length;){if(n[r]==="$"&&n[r+1]==="("&&n[r+2]==="("){let s=r+3,i=0;for(;s<n.length;){let o=n[s];if(o==="(")i++;else if(o===")"){if(i>0)i--;else if(n[s+1]===")"){let a=n.slice(r+3,s),c=wo(a,t);e+=Number.isNaN(c)?"0":String(c),r=s+2;break}}s++}if(s>=n.length){e+=n.slice(r);break}continue}e+=n[r],r++}return e}function cs(n,t,e=0,r){let s=r??t.HOME??"/home/user";return Dp(n,i=>{let o=i;return o=o.replace(/(^|[\s:])~(\/|$)/g,(a,c,l)=>`${c}${s}${l}`),o=o.replace(/\$\?/g,String(e)),o=o.replace(/\$\$/g,"1"),o=o.replace(/\$#/g,"0"),o=Mp(o,t),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,l)=>t[c]!==void 0&&t[c]!==""?t[c]:l),o=o.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*):=([^}]*)\}/g,(a,c,l)=>((t[c]===void 0||t[c]==="")&&(t[c]=l),t[c])),o=o.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*):\+([^}]*)\}/g,(a,c,l)=>t[c]!==void 0&&t[c]!==""?l:""),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_]*|\d+)/g,(a,c)=>t[c]??""),o})}async function fs(n,t,e,r){let s="__shellExpandDepth",o=Number(t[s]??"0");if(o>=8)return cs(n,t,e);t[s]=String(o+1);try{if(n.includes("$(")){let a="",c=!1,l=0;for(;l<n.length;){let f=n[l];if(f==="'"&&!c){c=!0,a+=f,l++;continue}if(f==="'"&&c){c=!1,a+=f,l++;continue}if(!c&&f==="$"&&n[l+1]==="("){if(n[l+2]==="("){a+=f,l++;continue}let u=0,h=l+1;for(;h<n.length;){if(n[h]==="(")u++;else if(n[h]===")"&&(u--,u===0))break;h++}let p=n.slice(l+2,h).trim(),A=(await r(p)).replace(/\n$/,"");a+=A,l=h+1;continue}a+=f,l++}n=a}return cs(n,t,e)}finally{o<=0?delete t[s]:t[s]=String(o)}}function Up(n){return n.replace(/\\n/g,`
81
- `).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 _l={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=cs(a,e?.vars??{},e?.lastExitCode??0),l=o?Up(c):c;return{stdout:i?l:`${l}
82
- `,exitCode:0}}};var Sl={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(`
83
- `),exitCode:0}}};var bl={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 xl={name:"export",description:"Set shell environment variable",category:"shell",params:["[VAR=value]"],run:({args:n,env:t})=>{if(n.length===0||n.length===1&&n[0]==="-p"){let e=Object.entries(t.vars).filter(([r])=>r&&/^[A-Za-z_][A-Za-z0-9_]*$/.test(r)).map(([r,s])=>`declare -x ${r}="${s}"`).join(`
84
- `);return{stdout:e?`${e}
85
- `:"",exitCode:0}}for(let e of n.filter(r=>r!=="-p"))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 wl={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=Jt(r,["-name"]),i=Jt(r,["-type"]),a=r.filter(h=>!h.startsWith("-")&&h!==s&&h!==i)[0]??".",c=de(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 l=s?new RegExp(`^${s.replace(/\./g,"\\.").replace(/\*/g,".*").replace(/\?/g,".")}$`):null,f=[],u=(h,p)=>{let A=t.vfs.stat(h),y=!i||i==="f"&&A.type==="file"||i==="d"&&A.type==="directory",b=!l||l.test(h.split("/").pop()??"");if(y&&b&&f.push(p),A.type==="directory")for(let x of t.vfs.list(h)){let B=`${h}/${x}`,H=`${p}/${x}`;u(B,H)}};return u(c,a),{stdout:f.join(`
86
- `),exitCode:0}}};var us=Wt(require("node:os"),1);var Il={name:"free",description:"Display amount of free and used memory",category:"system",params:["[-h] [-m] [-g]"],run:({args:n})=>{let t=se(n,["-h","--human"]),e=se(n,["-m"]),r=se(n,["-g"]),s=us.totalmem(),i=us.freemem(),o=s-i,a=Math.floor(s*.02),c=Math.floor(s*.05),l=Math.floor(i*.95),f=Math.floor(s*.5),u=y=>t?y>=1024*1024*1024?`${(y/(1024*1024*1024)).toFixed(1)}G`:y>=1024*1024?`${(y/(1024*1024)).toFixed(1)}M`:`${(y/1024).toFixed(1)}K`:String(Math.floor(r?y/(1024*1024*1024):e?y/(1024*1024):y/1024)),h=" total used free shared buff/cache available",p=`Mem: ${u(s).padStart(12)} ${u(o).padStart(11)} ${u(i).padStart(11)} ${u(a).padStart(11)} ${u(c).padStart(11)} ${u(l).padStart(11)}`,A=`Swap: ${u(f).padStart(12)} ${u(0).padStart(11)} ${u(f).padStart(11)}`;return{stdout:[h,p,A].join(`
87
- `),exitCode:0}}};var Cl={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","-c","-l","-L","-q","--quiet","--silent"]}),a=i.has("-i"),c=i.has("-v"),l=i.has("-n"),f=i.has("-r"),u=i.has("-c"),h=i.has("-l"),p=i.has("-q")||i.has("--quiet")||i.has("--silent"),A=o[0],y=o.slice(1);if(!A)return{stderr:"grep: no pattern specified",exitCode:1};let b;try{let C=a?"mi":"m";b=new RegExp(A,C)}catch{return{stderr:`grep: invalid regex: ${A}`,exitCode:1}}let x=(C,M="")=>{let Q=C.split(`
88
- `),N=[];for(let S=0;S<Q.length;S++){let w=Q[S]??"",v=b.test(w);if(c?!v:v){let P=l?`${S+1}:`:"";N.push(`${M}${P}${w}`)}}return N},B=C=>{if(!t.vfs.exists(C))return[];if(t.vfs.stat(C).type==="file")return[C];if(!f)return[];let Q=[],N=S=>{for(let w of t.vfs.list(S)){let v=`${S}/${w}`;t.vfs.stat(v).type==="file"?Q.push(v):N(v)}};return N(C),Q},H=[];if(y.length===0){if(!s)return{stdout:"",exitCode:1};let C=x(s);if(u)return{stdout:`${C.length}
89
- `,exitCode:C.length>0?0:1};if(p)return{exitCode:C.length>0?0:1};H.push(...C)}else{let C=y.flatMap(M=>{let Q=de(e,M);return B(Q).map(N=>({file:M,path:N}))});for(let{file:M,path:Q}of C)try{$e(n,Q,"grep");let N=t.vfs.readFile(Q),S=C.length>1?`${M}:`:"",w=x(N,S);u?H.push(C.length>1?`${M}:${w.length}`:String(w.length)):h?w.length>0&&H.push(M):H.push(...w)}catch{return{stderr:`grep: ${M}: No such file or directory`,exitCode:1}}}return{stdout:H.length>0?`${H.join(`
90
- `)}
91
- `:"",exitCode:H.length>0?0:1}}};var vl={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 kl={name:"gzip",description:"Compress files",category:"archive",params:["[-k] [-d] <file>"],run:({shell:n,cwd:t,args:e})=>{if(!n.packageManager.isInstalled("gzip"))return{stderr:`bash: gzip: command not found
92
- Hint: install it with: apt install gzip
93
- `,exitCode:127};let r=e.includes("-k")||e.includes("--keep"),s=e.includes("-d"),i=e.find(l=>!l.startsWith("-"));if(!i)return{stderr:`gzip: no file specified
94
- `,exitCode:1};let o=de(t,i);if(s){if(!i.endsWith(".gz"))return{stderr:`gzip: ${i}: unknown suffix -- ignored
95
- `,exitCode:1};if(!n.vfs.exists(o))return{stderr:`gzip: ${i}: No such file or directory
96
- `,exitCode:1};let l=n.vfs.readFile(o),f=o.slice(0,-3);return n.vfs.writeFile(f,l),r||n.vfs.remove(o),{exitCode:0}}if(!n.vfs.exists(o))return{stderr:`gzip: ${i}: No such file or directory
97
- `,exitCode:1};if(i.endsWith(".gz"))return{stderr:`gzip: ${i}: already has .gz suffix -- unchanged
98
- `,exitCode:1};let a=n.vfs.readFileRaw(o),c=`${o}.gz`;return n.vfs.writeFile(c,a,{compress:!0}),r||n.vfs.remove(o),{exitCode:0}}},Nl={name:"gunzip",description:"Decompress files",category:"archive",aliases:["zcat"],params:["[-k] <file>"],run:({shell:n,cwd:t,args:e})=>{let r=e.includes("-k")||e.includes("--keep"),s=e.find(c=>!c.startsWith("-"));if(!s)return{stderr:`gunzip: no file specified
99
- `,exitCode:1};let i=de(t,s);if(!n.vfs.exists(i))return{stderr:`gunzip: ${s}: No such file or directory
100
- `,exitCode:1};if(!s.endsWith(".gz"))return{stderr:`gunzip: ${s}: unknown suffix -- ignored
101
- `,exitCode:1};let o=n.vfs.readFile(i),a=i.slice(0,-3);return n.vfs.writeFile(a,o),r||n.vfs.remove(i),{exitCode:0}}};var Bl={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=Jt(r,["-n"]),o=r.find(u=>/^-\d+$/.test(u)),a=typeof i=="string"?parseInt(i,10):o?parseInt(o.slice(1),10):10,c=r.filter(u=>!u.startsWith("-")&&u!==i&&u!==String(a)),l=u=>{let h=u.split(`
102
- `),p=h.slice(0,a);return p.join(`
103
- `)+(u.endsWith(`
104
- `)&&p.length===h.slice(0,a).length?`
105
- `:"")};if(c.length===0)return{stdout:l(s??""),exitCode:0};let f=[];for(let u of c){let h=de(e,u);try{$e(n,h,"head"),f.push(l(t.vfs.readFile(h)))}catch{return{stderr:`head: ${u}: No such file or directory`,exitCode:1}}}return{stdout:f.join(`
106
- `),exitCode:0}}};var Rl=["navigation","files","text","archive","system","package","network","shell","users","misc"],Tl={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"},Ol="\x1B[1m",kn="\x1B[0m",$p="\x1B[36m",Fp="\x1B[33m",hi="\x1B[2m",Hp="\x1B[32m";function Pl(n,t){return n.length>=t?n:n+" ".repeat(t-n.length)}function Qp(n){let t=n.aliases?.length?` ${hi}(${n.aliases.join(", ")})${kn}`:"";return` ${$p}${Pl(n.name,16)}${kn}${t}${Pl("",(n.aliases?.length,0))} ${n.description??""}`}function Wp(n){let t={};for(let i of n){let o=i.category??"misc";t[o]||(t[o]=[]),t[o].push(i)}let e=[`${Ol}Available commands${kn}`,`${hi}Type 'help <command>' for detailed usage.${kn}`,""],r=[...Rl.filter(i=>t[i]),...Object.keys(t).filter(i=>!Rl.includes(i)).sort()];for(let i of r){let o=t[i];if(!o?.length)continue;e.push(`${Fp}${Tl[i]??i}${kn}`);let a=[...o].sort((c,l)=>c.name.localeCompare(l.name));for(let c of a)e.push(Qp(c));e.push("")}let s=n.length;return e.push(`${hi}${s} commands available.${kn}`),e.join(`
107
- `)}function qp(n){let t=[];if(t.push(`${Ol}${n.name}${kn} \u2014 ${n.description??"no description"}`),n.aliases?.length&&t.push(`${hi}Aliases: ${n.aliases.join(", ")}${kn}`),t.push(""),t.push(`${Hp}Usage:${kn}`),n.params.length)for(let r of n.params)t.push(` ${n.name} ${r}`);else t.push(` ${n.name}`);let e=Tl[n.category??"misc"]??n.category??"misc";return t.push(""),t.push(`${hi}Category: ${e}${kn}`),t.join(`
108
- `)}function Ll(n){return{name:"help",description:"List all commands, or show usage for a specific command",category:"shell",params:["[command]"],run:({args:t})=>{let e=Io();if(t[0]){let r=t[0].toLowerCase(),s=e.find(i=>i.name===r||i.aliases?.includes(r));return s?{stdout:qp(s),exitCode:0}:{stderr:`help: no help entry for '${t[0]}'`,exitCode:1}}return{stdout:Wp(e),exitCode:0}}}}var Dl={name:"history",description:"Display command history",category:"shell",params:["[n]"],run:({args:n,shell:t,authUser:e})=>{let r=`/home/${e}/.bash_history`;if(!t.vfs.exists(r))return{stdout:"",exitCode:0};let i=t.vfs.readFile(r).split(`
109
- `).filter(Boolean),o=n[0],a=o?parseInt(o,10):null,c=a&&!Number.isNaN(a)?i.slice(-a):i,l=i.length-c.length+1;return{stdout:c.map((u,h)=>`${String(l+h).padStart(5)} ${u}`).join(`
110
- `),exitCode:0}}};var Ml={name:"hostname",description:"Print hostname",category:"system",params:[],run:({hostname:n})=>({stdout:n,exitCode:0})};var Ul={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 $l={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 Fl={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 Hl={name:"ln",description:"Create links",category:"files",params:["[-s] <target> <link_name>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=se(r,["-s","--symbolic"]),i=r.filter(f=>!f.startsWith("-")),[o,a]=i;if(!o||!a)return{stderr:"ln: missing operand",exitCode:1};let c=de(e,a),l=s?o:de(e,o);try{if($e(n,c,"ln"),s)t.vfs.symlink(l,c);else{let f=de(e,o);if($e(n,f,"ln"),!t.vfs.exists(f))return{stderr:`ln: ${o}: No such file or directory`,exitCode:1};let u=t.vfs.readFile(f);t.writeFileAsUser(n,c,u)}return{exitCode:0}}catch(f){return{stderr:`ln: ${f instanceof Error?f.message:String(f)}`,exitCode:1}}}},Ql={name:"readlink",description:"Print resolved path of symbolic link",category:"files",params:["[-f] <path>"],run:({shell:n,cwd:t,args:e})=>{let r=e.includes("-f")||e.includes("-e"),s=e.find(a=>!a.startsWith("-"));if(!s)return{stderr:`readlink: missing operand
111
- `,exitCode:1};let i=de(t,s);return n.vfs.exists(i)?n.vfs.isSymlink(i)?{stdout:`${n.vfs.resolveSymlink(i)}
112
- `,exitCode:0}:{stderr:`readlink: ${s}: not a symbolic link
113
- `,exitCode:1}:{stderr:`readlink: ${s}: No such file or directory
114
- `,exitCode:1}}};var Wl={name:"seq",description:"Print a sequence of numbers",category:"text",params:["[FIRST [INCREMENT]] LAST"],run:({args:n})=>{let t=n.filter(u=>!u.startsWith("-")||/^-[\d.]/.test(u)).map(Number),e=(()=>{let u=n.indexOf("-s");return u!==-1?n[u+1]??`
115
- `:`
116
- `})(),r=(()=>{let u=n.indexOf("-f");return u!==-1?n[u+1]??"%g":null})(),s=n.includes("-w"),i=1,o=1,a;if(t.length===1?a=t[0]:t.length===2?(i=t[0],a=t[1]):(i=t[0],o=t[1],a=t[2]),o===0)return{stderr:`seq: zero increment
117
- `,exitCode:1};if(o>0&&i>a||o<0&&i<a)return{stdout:"",exitCode:0};let c=[],l=1e5,f=0;for(let u=i;(o>0?u<=a:u>=a)&&!(++f>l);u=Math.round((u+o)*1e10)/1e10){let h;if(r?h=r.replace("%g",String(u)).replace("%f",u.toFixed(6)).replace("%d",String(Math.trunc(u))):h=Number.isInteger(u)?String(u):u.toPrecision(12).replace(/\.?0+$/,""),s){let p=String(Math.trunc(a)).length;h=h.padStart(p,"0")}c.push(h)}return{stdout:`${c.join(e)}
118
- `,exitCode:0}}};var ql={name:"stat",description:"Display file status",category:"files",params:["[-c <format>] <file>"],run:({shell:n,cwd:t,args:e})=>{let r=e.findIndex(x=>x==="-c"||x==="--format"),s=r!==-1?e[r+1]:void 0,i=e.find(x=>!x.startsWith("-")&&x!==s);if(!i)return{stderr:`stat: missing operand
119
- `,exitCode:1};let o=de(t,i);if(!n.vfs.exists(o))return{stderr:`stat: cannot stat '${i}': No such file or directory
120
- `,exitCode:1};let a=n.vfs.stat(o),c=a.type==="directory",l=n.vfs.isSymlink(o),f=n.vfs.isSymlink(o),u=x=>{let B=[256,128,64,32,16,8,4,2,1],H=["r","w","x","r","w","x","r","w","x"];return(c?"d":f?"l":"-")+B.map((C,M)=>x&C?H[M]:"-").join("")},h=a.mode.toString(8).padStart(4,"0"),p=u(a.mode),A="size"in a?a.size:0,y=x=>x.toISOString().replace("T"," ").replace(/\.\d+Z$/," +0000");return s?{stdout:`${s.replace("%n",i).replace("%s",String(A)).replace("%a",h.slice(1)).replace("%A",p).replace("%F",f?"symbolic link":c?"directory":"regular file").replace("%y",y(a.updatedAt)).replace("%z",y(a.updatedAt))}
121
- `,exitCode:0}:{stdout:`${[` File: ${i}${f?` -> ${n.vfs.resolveSymlink(o)}`:""}`,` Size: ${A}${" ".repeat(3)}${f?"symbolic link":c?"directory":"regular file"}`,`Access: (${h}/${p}) Uid: ( 0/ root) Gid: ( 0/ root)`,`Modify: ${y(a.updatedAt)}`,`Change: ${y(a.updatedAt)}`].join(`
122
- `)}
123
- `,exitCode:0}}};var Kp="\x1B[0m",Vp="\x1B[1;34m",zp="\x1B[1;36m",Yp="\x1B[1;32m",Gp="",jp="\x1B[30;42m",Xp="\x1B[37;44m",Jp="\x1B[34;42m";function Rr(n,t){return t?`${t}${n}${Kp}`:n}function vo(n,t,e){if(e)return zp;if(t==="directory"){let r=!!(n&512),s=!!(n&2);return r&&s?jp:r?Xp:s?Jp:Vp}return n&73?Yp:Gp}function Kl(n,t,e){let r;e?r="l":t==="directory"?r="d":r="-";let s=l=>n&l?"r":"-",i=l=>n&l?"w":"-",o=(()=>{let l=!!(n&64);return n&2048?l?"s":"S":l?"x":"-"})(),a=(()=>{let l=!!(n&8);return n&1024?l?"s":"S":l?"x":"-"})(),c=(()=>{let l=!!(n&1);return t==="directory"&&n&512?l?"t":"T":l?"x":"-"})();return`${r}${s(256)}${i(128)}${o}${s(32)}${i(16)}${a}${s(4)}${i(2)}${c}`}var Zp=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function Co(n){let t=new Date,e=4320*3600*1e3,r=Math.abs(t.getTime()-n.getTime())<e,s=String(n.getDate()).padStart(2," "),i=Zp[n.getMonth()]??"";if(r){let o=String(n.getHours()).padStart(2,"0"),a=String(n.getMinutes()).padStart(2,"0");return`${s} ${i.padEnd(3)} ${o}:${a}`}return`${s} ${i.padEnd(3)} ${n.getFullYear()}`}function ds(n,t){try{return n.readFile(t)}catch{return"?"}}function em(n,t,e){let r=t==="/"?"":t;return e.map(s=>{let i=`${r}/${s}`,o=n.isSymlink(i),a;try{a=n.stat(i)}catch{return s}let c=vo(a.mode,a.type,o);return Rr(s,c)}).join(" ")}function tm(n,t,e){let r=t==="/"?"":t,s=e.map(u=>{let h=`${r}/${u}`,p=n.isSymlink(h),A;try{A=n.stat(h)}catch{return{perms:"----------",nlink:"1",size:"0",date:Co(new Date),label:u}}let y=p?41471:A.mode,b=Kl(y,A.type,p),x=A.type==="directory"?String((A.childrenCount??0)+2):"1",B=p?ds(n,h).length:A.type==="file"?A.size??0:(A.childrenCount??0)*4096,H=String(B),C=Co(A.updatedAt),M=vo(y,A.type,p),Q=p?`${Rr(u,M)} -> ${ds(n,h)}`:Rr(u,M);return{perms:b,nlink:x,size:H,date:C,label:Q}}),i=Math.max(...s.map(u=>u.nlink.length)),o=Math.max(...s.map(u=>u.size.length)),a="root",c="root",l=e.length*8,f=s.map(u=>`${u.perms} ${u.nlink.padStart(i)} ${a} ${c} ${u.size.padStart(o)} ${u.date} ${u.label}`);return`total ${l}
124
- ${f.join(`
125
- `)}`}var Vl={name:"ls",description:"List directory contents",category:"navigation",params:["[-la] [path]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=se(r,["-l","--long","-la","-al"]),i=se(r,["-a","--all","-la","-al"]),o=Mn(r,0,{flags:["-l","--long","-a","--all","-la","-al"]}),a=de(e,o??e);if($e(n,a,"ls"),t.vfs.exists(a)){let f=t.vfs.stat(a),u=t.vfs.isSymlink(a);if(f.type==="file"||u){let h=a.split("/").pop()??a,p=vo(u?41471:f.mode,f.type,u);if(s){let A=u?41471:f.mode,y=u?ds(t.vfs,a).length:f.size??0,b=Kl(A,f.type,u),x=u?`${Rr(h,p)} -> ${ds(t.vfs,a)}`:Rr(h,p);return{stdout:`${b} 1 root root ${y} ${Co(f.updatedAt)} ${x}
126
- `,exitCode:0}}return{stdout:`${Rr(h,p)}
127
- `,exitCode:0}}}let c=t.vfs.list(a).filter(f=>i||!f.startsWith("."));return{stdout:`${s?tm(t.vfs,a,c):em(t.vfs,a,c)}
128
- `,exitCode:0}}};var zl={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(`
129
- `))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=se(n,["-a","--all"]),o=se(n,["-i","--id"]),a=se(n,["-d","--description"]),c=se(n,["-r","--release"]),l=se(n,["-c","--codename"]);if(i||n.length===0)return{stdout:["Distributor ID: Fortune",`Description: ${e}`,`Release: ${s}`,`Codename: ${r}`].join(`
130
- `),exitCode:0};let f=[];return o&&f.push("Distributor ID: Fortune"),a&&f.push(`Description: ${e}`),c&&f.push(`Release: ${s}`),l&&f.push(`Codename: ${r}`),{stdout:f.join(`
131
- `),exitCode:0}}};var Yl={adduser:`ADDUSER(8) User Commands ADDUSER(8)
132
-
133
- NAME
134
- adduser - add a user to the system
135
-
136
- SYNOPSIS
137
- adduser USERNAME
138
-
139
- DESCRIPTION
140
- Create a new user account with a home directory.
141
- In this environment, prompts for a password interactively.`,"apt-cache":`APT-CACHE(8) APT APT-CACHE(8)
142
-
143
- NAME
144
- apt-cache - query APT package cache
145
-
146
- SYNOPSIS
147
- apt-cache command [args]
148
-
149
- COMMANDS
150
- search term search package names/descriptions
151
- show pkg show package metadata
152
- policy pkg show package policy and candidate versions`,apt:`APT(8) APT APT(8)
153
-
154
- NAME
155
- apt - command-line interface
156
-
157
- SYNOPSIS
158
- apt [options] command
159
-
160
- DESCRIPTION
161
- apt provides a high-level commandline interface for the package
162
- management system.
163
-
164
- COMMANDS
165
- install pkg... Install packages
166
- remove pkg... Remove packages
167
- update Download package information
168
- upgrade Upgrade installed packages
169
- search term Search in package descriptions
170
- show pkg Show package information
171
- list List packages`,awk:`AWK(1) User Commands AWK(1)
172
-
173
- NAME
174
- awk - pattern scanning and processing language
175
-
176
- SYNOPSIS
177
- awk [OPTION]... 'PROGRAM' [FILE]...
178
-
179
- DESCRIPTION
180
- awk scans each input line, applies PROGRAM rules, and prints results.
181
-
182
- OPTIONS
183
- -F fs use fs as input field separator`,cat:`CAT(1) User Commands CAT(1)
184
-
185
- NAME
186
- cat - concatenate files and print on the standard output
187
-
188
- SYNOPSIS
189
- cat [OPTION]... [FILE]...
190
-
191
- DESCRIPTION
192
- Concatenate FILE(s) to standard output.
193
-
194
- OPTIONS
195
- -n, --number number all output lines
196
- -b, --number-nonblank number nonempty output lines`,cd:`CD(1) Shell Builtins CD(1)
197
-
198
- NAME
199
- cd - change the shell working directory
200
-
201
- SYNOPSIS
202
- cd [DIRECTORY]
203
-
204
- DESCRIPTION
205
- Change the current working directory.
206
- Without DIRECTORY, changes to $HOME.
207
-
208
- EXAMPLES
209
- cd /etc
210
- cd ..
211
- cd ~`,chmod:`CHMOD(1) User Commands CHMOD(1)
212
-
213
- NAME
214
- chmod - change file mode bits
215
-
216
- SYNOPSIS
217
- chmod [OPTION]... MODE[,MODE]... FILE...
218
- chmod [OPTION]... OCTAL-MODE FILE...
219
-
220
- DESCRIPTION
221
- Change the file mode bits of each given file according to MODE.
222
-
223
- EXAMPLES
224
- chmod 755 script.sh rwxr-xr-x
225
- chmod 644 file.txt rw-r--r--
226
- chmod +x script.sh add execute permission`,clear:`CLEAR(1) User Commands CLEAR(1)
227
-
228
- NAME
229
- clear - clear the terminal screen
230
-
231
- SYNOPSIS
232
- clear
233
-
234
- DESCRIPTION
235
- Clear the display and move cursor to top-left.`,cp:`CP(1) User Commands CP(1)
236
-
237
- NAME
238
- cp - copy files and directories
239
-
240
- SYNOPSIS
241
- cp [OPTION]... SOURCE... DEST
242
-
243
- OPTIONS
244
- -r copy directories recursively`,curl:`CURL(1) User Commands CURL(1)
245
-
246
- NAME
247
- curl - transfer a URL
248
-
249
- SYNOPSIS
250
- curl [options / URLs]
251
-
252
- DESCRIPTION
253
- curl is a tool for transferring data with URL syntax.
254
-
255
- OPTIONS
256
- -o, --output <file> Write output to <file>
257
- -X, --request <method> Specify request method
258
- -d, --data <data> HTTP POST data
259
- -H, --header <header> Pass custom header
260
- -s, --silent Silent mode
261
- -I, --head Show document info only
262
- -L, --location Follow redirects
263
- -v, --verbose Make the operation more talkative`,date:`DATE(1) User Commands DATE(1)
264
-
265
- NAME
266
- date - print or set the system date and time
267
-
268
- SYNOPSIS
269
- date [+FORMAT]
270
-
271
- DESCRIPTION
272
- Display current date/time, optionally formatted.
273
-
274
- EXAMPLES
275
- date
276
- date +%Y-%m-%d`,declare:`DECLARE(1) Shell Builtins DECLARE(1)
277
-
278
- NAME
279
- declare - set variable values and attributes
280
-
281
- SYNOPSIS
282
- declare [OPTION]... [NAME[=VALUE]...]
283
-
284
- OPTIONS
285
- -i variable has integer attribute
286
- -r make NAMEs readonly
287
- -x export NAMEs to environment`,deluser:`DELUSER(8) User Commands DELUSER(8)
288
-
289
- NAME
290
- deluser - remove a user account
291
-
292
- SYNOPSIS
293
- deluser [OPTION] USERNAME
294
-
295
- OPTIONS
296
- -f, --force remove without interactive confirmation`,df:`DF(1) User Commands DF(1)
297
-
298
- NAME
299
- df - report file system disk space usage
300
-
301
- SYNOPSIS
302
- df [OPTION]... [FILE]...
303
-
304
- OPTIONS
305
- -h print sizes in human readable format`,"dpkg-query":`DPKG-QUERY(1) User Commands DPKG-QUERY(1)
306
-
307
- NAME
308
- dpkg-query - tool to query the dpkg database
309
-
310
- SYNOPSIS
311
- dpkg-query [OPTION]... [ACTION]
312
-
313
- OPTIONS
314
- -W list installed packages (show format)
315
- -l list packages`,dpkg:`DPKG(1) User Commands DPKG(1)
316
-
317
- NAME
318
- dpkg - package manager for Debian-like systems
319
-
320
- SYNOPSIS
321
- dpkg [OPTION]... ACTION
322
-
323
- OPTIONS
324
- -l list installed packages
325
- -s show package status
326
- -L list files in package
327
- -r remove package
328
- -P purge package`,du:`DU(1) User Commands DU(1)
329
-
330
- NAME
331
- du - estimate file space usage
332
-
333
- SYNOPSIS
334
- du [OPTION]... [FILE]...
335
-
336
- OPTIONS
337
- -h print sizes in human readable format
338
- -s display only a total for each argument`,echo:`ECHO(1) User Commands ECHO(1)
339
-
340
- NAME
341
- echo - display a line of text
342
-
343
- SYNOPSIS
344
- echo [OPTION]... [STRING]...
345
-
346
- OPTIONS
347
- -n do not output the trailing newline
348
- -e enable interpretation of backslash escapes`,false:`FALSE(1) User Commands FALSE(1)
349
-
350
- NAME
351
- false - do nothing, unsuccessfully
352
-
353
- SYNOPSIS
354
- false
355
-
356
- DESCRIPTION
357
- Exit with a status code indicating failure (1).`,find:`FIND(1) User Commands FIND(1)
358
-
359
- NAME
360
- find - search for files in a directory hierarchy
361
-
362
- SYNOPSIS
363
- find [PATH] [EXPRESSION]
364
-
365
- OPTIONS
366
- -name PATTERN base name matches shell PATTERN
367
- -type TYPE file type, e.g. f for file, d for directory`,free:`FREE(1) User Commands FREE(1)
368
-
369
- NAME
370
- free - display amount of free and used memory in the system
371
-
372
- SYNOPSIS
373
- free [OPTION]...
374
-
375
- OPTIONS
376
- -h show all output fields automatically scaled
377
- -m show output in mebibytes
378
- -g show output in gibibytes`,grep:`GREP(1) User Commands GREP(1)
379
-
380
- NAME
381
- grep, egrep, fgrep - print lines that match patterns
382
-
383
- SYNOPSIS
384
- grep [OPTION]... PATTERNS [FILE]...
385
-
386
- OPTIONS
387
- -i, --ignore-case ignore case distinctions in patterns and data
388
- -v, --invert-match select non-matching lines
389
- -n, --line-number print line number with output lines
390
- -r, --recursive read all files under each directory, recursively`,groups:`GROUPS(1) User Commands GROUPS(1)
391
-
392
- NAME
393
- groups - print the groups a user is in
394
-
395
- SYNOPSIS
396
- groups [USER]
397
-
398
- DESCRIPTION
399
- Print group memberships for USER or current user if omitted.`,gzip:`GZIP(1) User Commands GZIP(1)
400
-
401
- NAME
402
- gzip, gunzip - compress or expand files
403
-
404
- SYNOPSIS
405
- gzip FILE...
406
- gunzip FILE...
407
-
408
- DESCRIPTION
409
- Compress or decompress files in place.`,head:`HEAD(1) User Commands HEAD(1)
410
-
411
- NAME
412
- head - output the first part of files
413
-
414
- SYNOPSIS
415
- head [OPTION]... [FILE]...
416
-
417
- OPTIONS
418
- -n, --lines=[-]NUM print the first NUM lines`,help:`HELP(1) Shell Builtins HELP(1)
419
-
420
- NAME
421
- help - display information about builtin commands
422
-
423
- SYNOPSIS
424
- help [COMMAND]
425
-
426
- DESCRIPTION
427
- With no arguments, list available commands.
428
- With COMMAND, show usage details for that command.`,history:`HISTORY(1) Shell Builtins HISTORY(1)
429
-
430
- NAME
431
- history - command history list
432
-
433
- SYNOPSIS
434
- history [N]
435
-
436
- DESCRIPTION
437
- Print recent command history entries.
438
- If N is provided, print only the last N entries.`,hostname:`HOSTNAME(1) User Commands HOSTNAME(1)
439
-
440
- NAME
441
- hostname - show or set the system host name
442
-
443
- SYNOPSIS
444
- hostname
445
-
446
- DESCRIPTION
447
- Print the current host name.`,id:`ID(1) User Commands ID(1)
448
-
449
- NAME
450
- id - print real and effective user and group IDs
451
-
452
- SYNOPSIS
453
- id [USER]
454
-
455
- DESCRIPTION
456
- Print user identity information including uid, gid, and groups.`,kill:`KILL(1) User Commands KILL(1)
457
-
458
- NAME
459
- kill - send signals to processes
460
-
461
- SYNOPSIS
462
- kill [-SIGNAL] PID...
463
-
464
- DESCRIPTION
465
- Send a signal to one or more process IDs.
466
-
467
- NOTES
468
- This environment provides a mock process model.`,ls:`LS(1) User Commands LS(1)
469
-
470
- NAME
471
- ls - list directory contents
472
-
473
- SYNOPSIS
474
- ls [OPTION]... [FILE]...
475
-
476
- DESCRIPTION
477
- List information about the FILEs (the current directory by default).
478
-
479
- OPTIONS
480
- -l use a long listing format
481
- -a do not ignore entries starting with .
482
- -h with -l, print human readable sizes
483
- -r reverse order while sorting
484
- -t sort by modification time
485
-
486
- AUTHOR
487
- Written by Richard M. Stallman and David MacKenzie.`,lsb_release:`LSB_RELEASE(1) User Commands LSB_RELEASE(1)
488
-
489
- NAME
490
- lsb_release - print distribution-specific information
491
-
492
- SYNOPSIS
493
- lsb_release [OPTION]...
494
-
495
- OPTIONS
496
- -a show all available information
497
- -i show distributor ID
498
- -d show description
499
- -r show release number
500
- -c show codename`,mkdir:`MKDIR(1) User Commands MKDIR(1)
501
-
502
- NAME
503
- mkdir - make directories
504
-
505
- SYNOPSIS
506
- mkdir [OPTION]... DIRECTORY...
507
-
508
- OPTIONS
509
- -p no error if existing, make parent directories as needed`,mv:`MV(1) User Commands MV(1)
510
-
511
- NAME
512
- mv - move (rename) files
513
-
514
- SYNOPSIS
515
- mv SOURCE DEST
516
-
517
- DESCRIPTION
518
- Rename SOURCE to DEST, or move SOURCE into a destination directory.`,nano:`NANO(1) User Commands NANO(1)
519
-
520
- NAME
521
- nano - simple terminal text editor
522
-
523
- SYNOPSIS
524
- nano FILE
525
-
526
- DESCRIPTION
527
- Open FILE in an interactive editor.
528
- Save with Ctrl+O, exit with Ctrl+X.`,neofetch:`NEOFETCH(1) User Commands NEOFETCH(1)
529
-
530
- NAME
531
- neofetch - display system information
532
-
533
- SYNOPSIS
534
- neofetch
535
-
536
- DESCRIPTION
537
- Print OS, kernel, uptime, package count, and related system details.`,node:`NODE(1) User Commands NODE(1)
538
-
539
- NAME
540
- node - virtual JavaScript runtime entry point
541
-
542
- SYNOPSIS
543
- node [--version] [-e SCRIPT] [-p EXPR]
544
-
545
- DESCRIPTION
546
- Execute JavaScript snippets in the virtual runtime.
547
-
548
- NOTES
549
- Requires package installation: apt install nodejs.`,npm:`NPM(1) User Commands NPM(1)
550
-
551
- NAME
552
- npm - virtual Node.js package manager interface
553
-
554
- SYNOPSIS
555
- npm [--version] [COMMAND]
556
-
557
- DESCRIPTION
558
- Manage packages and run scripts in the virtual environment.
559
-
560
- NOTES
561
- Requires package installation: apt install npm.`,npx:`NPX(1) User Commands NPX(1)
562
-
563
- NAME
564
- npx - execute package binaries from npm
565
-
566
- SYNOPSIS
567
- npx [--version] <command>
568
-
569
- DESCRIPTION
570
- Run package executables in the virtual environment.
571
-
572
- NOTES
573
- Requires package installation: apt install npm.`,passwd:`PASSWD(1) User Commands PASSWD(1)
574
-
575
- NAME
576
- passwd - change user password
577
-
578
- SYNOPSIS
579
- passwd [USER]
580
-
581
- DESCRIPTION
582
- Update the authentication token (password) for USER.
583
- Without USER, change the current user's password.`,ping:`PING(8) User Commands PING(8)
584
-
585
- NAME
586
- ping - send ICMP ECHO_REQUEST to network hosts
587
-
588
- SYNOPSIS
589
- ping [-c COUNT] DESTINATION
590
-
591
- OPTIONS
592
- -c COUNT stop after sending COUNT packets`,printf:`PRINTF(1) User Commands PRINTF(1)
593
-
594
- NAME
595
- printf - format and print data
596
-
597
- SYNOPSIS
598
- printf FORMAT [ARGUMENT]...
599
-
600
- DESCRIPTION
601
- Print ARGUMENT(s) according to FORMAT.
602
- Supports common conversions like %s, %d, %f, %x and escapes like \\n.`,ps:`PS(1) User Commands PS(1)
603
-
604
- NAME
605
- ps - report a snapshot of current processes
606
-
607
- SYNOPSIS
608
- ps [OPTION]
609
-
610
- DESCRIPTION
611
- Show process information for active sessions and commands.`,pwd:`PWD(1) User Commands PWD(1)
612
-
613
- NAME
614
- pwd - print name of current working directory
615
-
616
- SYNOPSIS
617
- pwd
618
-
619
- DESCRIPTION
620
- Print the absolute path of the current directory.`,python3:`PYTHON3(1) User Commands PYTHON3(1)
621
-
622
- NAME
623
- python3 - virtual Python 3 interpreter entry point
624
-
625
- SYNOPSIS
626
- python3 [--version] [-V] [-c COMMAND]
627
-
628
- DESCRIPTION
629
- Execute Python snippets in the virtual runtime.
630
-
631
- NOTES
632
- Requires package installation: apt install python3.`,readlink:`READLINK(1) User Commands READLINK(1)
633
-
634
- NAME
635
- readlink - print resolved symbolic links or canonical file names
636
-
637
- SYNOPSIS
638
- readlink [OPTION]... FILE
639
-
640
- OPTIONS
641
- -f canonicalize by following every symlink in every component`,return:`RETURN(1) Shell Builtins RETURN(1)
642
-
643
- NAME
644
- return - return from a shell function
645
-
646
- SYNOPSIS
647
- return [N]
648
-
649
- DESCRIPTION
650
- Cause a function to exit with status N (default: last status).`,rm:`RM(1) User Commands RM(1)
651
-
652
- NAME
653
- rm - remove files or directories
654
-
655
- SYNOPSIS
656
- rm [OPTION]... FILE...
657
-
658
- OPTIONS
659
- -r remove directories and their contents recursively`,sed:`SED(1) User Commands SED(1)
660
-
661
- NAME
662
- sed - stream editor for filtering and transforming text
663
-
664
- SYNOPSIS
665
- sed [OPTION]... {-e script} [FILE]...
666
-
667
- OPTIONS
668
- -e SCRIPT add SCRIPT to commands to be executed
669
- -i edit files in place`,set:`SET(1) Shell Builtins SET(1)
670
-
671
- NAME
672
- set - set or unset shell options and positional parameters
673
-
674
- SYNOPSIS
675
- set [OPTION]... [ARG]...
676
- set [NAME=VALUE]...
677
-
678
- DESCRIPTION
679
- Display or modify shell variable state.`,shift:`SHIFT(1) Shell Builtins SHIFT(1)
680
-
681
- NAME
682
- shift - shift positional parameters
683
-
684
- SYNOPSIS
685
- shift [N]
686
-
687
- DESCRIPTION
688
- Rename positional parameters by discarding the first N arguments.`,sleep:`SLEEP(1) User Commands SLEEP(1)
689
-
690
- NAME
691
- sleep - delay for a specified amount of time
692
-
693
- SYNOPSIS
694
- sleep NUMBER
695
-
696
- DESCRIPTION
697
- Pause execution for NUMBER seconds.`,sort:`SORT(1) User Commands SORT(1)
698
-
699
- NAME
700
- sort - sort lines of text files
701
-
702
- SYNOPSIS
703
- sort [OPTION]... [FILE]...
704
-
705
- OPTIONS
706
- -r reverse the result of comparisons
707
- -n compare according to string numerical value
708
- -u output only the first of an equal run`,source:`SOURCE(1) Shell Builtins SOURCE(1)
709
-
710
- NAME
711
- source - execute commands from a file in the current shell
712
-
713
- SYNOPSIS
714
- source FILE
715
- . FILE
716
-
717
- DESCRIPTION
718
- Read and execute commands from FILE in the current shell context.`,ssh:`SSH(1) OpenSSH SSH(1)
719
-
720
- NAME
721
- ssh - OpenSSH remote login client
722
-
723
- SYNOPSIS
724
- ssh [-p port] [user@]hostname [command]
725
-
726
- DESCRIPTION
727
- ssh (SSH client) is a program for logging into a remote machine and
728
- for executing commands on a remote machine.`,stat:`STAT(1) User Commands STAT(1)
729
-
730
- NAME
731
- stat - display file status
732
-
733
- SYNOPSIS
734
- stat [OPTION]... FILE...
735
-
736
- OPTIONS
737
- -c, --format=FORMAT use the specified output format`,su:`SU(1) User Commands SU(1)
738
-
739
- NAME
740
- su - run a command with substitute user and group ID
741
-
742
- SYNOPSIS
743
- su [OPTION]... [USER]
744
-
745
- OPTIONS
746
- - start a login shell
747
-
748
- DESCRIPTION
749
- Switch to another user account in the current session.`,sudo:`SUDO(8) User Commands SUDO(8)
750
-
751
- NAME
752
- sudo - execute a command as another user
753
-
754
- SYNOPSIS
755
- sudo [OPTION]... COMMAND [ARG]...
756
-
757
- OPTIONS
758
- -i run login shell as target user
759
- -u USER run command as USER`,tail:`TAIL(1) User Commands TAIL(1)
760
-
761
- NAME
762
- tail - output the last part of files
763
-
764
- SYNOPSIS
765
- tail [OPTION]... [FILE]...
766
-
767
- OPTIONS
768
- -n, --lines=[+]NUM output the last NUM lines`,tar:`TAR(1) GNU tar Manual TAR(1)
769
-
770
- NAME
771
- tar - an archiving utility
772
-
773
- SYNOPSIS
774
- tar [OPTION...] [FILE]...
775
-
776
- DESCRIPTION
777
- tar saves many files together into a single tape or disk archive,
778
- and can restore individual files from the archive.
779
-
780
- OPTIONS
781
- -c, --create create a new archive
782
- -x, --extract extract files from an archive
783
- -z, --gzip filter the archive through gzip
784
- -f, --file=ARCHIVE use archive file or device ARCHIVE
785
- -v, --verbose verbosely list files processed
786
- -t, --list list the contents of an archive`,tee:`TEE(1) User Commands TEE(1)
787
-
788
- NAME
789
- tee - read from standard input and write to standard output and files
790
-
791
- SYNOPSIS
792
- tee [OPTION]... [FILE]...
793
-
794
- OPTIONS
795
- -a append to the given FILEs, do not overwrite`,test:`TEST(1) Shell Builtins TEST(1)
796
-
797
- NAME
798
- test - check file types and compare values
799
-
800
- SYNOPSIS
801
- test EXPRESSION
802
- [ EXPRESSION ]
803
-
804
- DESCRIPTION
805
- Evaluate conditional expressions for scripts and shell logic.`,touch:`TOUCH(1) User Commands TOUCH(1)
806
-
807
- NAME
808
- touch - change file timestamps / create file
809
-
810
- SYNOPSIS
811
- touch FILE...
812
-
813
- DESCRIPTION
814
- Update access and modification times.
815
- If FILE does not exist, create an empty file.`,tr:`TR(1) User Commands TR(1)
816
-
817
- NAME
818
- tr - translate or delete characters
819
-
820
- SYNOPSIS
821
- tr [OPTION]... SET1 [SET2]
822
-
823
- OPTIONS
824
- -d delete characters in SET1 instead of translating`,trap:`TRAP(1) Shell Builtins TRAP(1)
825
-
826
- NAME
827
- trap - trap signals and other events
828
-
829
- SYNOPSIS
830
- trap [ACTION] [SIGNAL]...
831
-
832
- DESCRIPTION
833
- Define or clear handlers for shell signals and EXIT.`,true:`TRUE(1) User Commands TRUE(1)
834
-
835
- NAME
836
- true - do nothing, successfully
837
-
838
- SYNOPSIS
839
- true
840
-
841
- DESCRIPTION
842
- Exit with a status code indicating success (0).`,type:`TYPE(1) Shell Builtins TYPE(1)
843
-
844
- NAME
845
- type - display how a command name is interpreted
846
-
847
- SYNOPSIS
848
- type NAME...
849
-
850
- DESCRIPTION
851
- Indicate whether NAME is a shell builtin, alias, or found in PATH.`,uname:`UNAME(1) User Commands UNAME(1)
852
-
853
- NAME
854
- uname - print system information
855
-
856
- SYNOPSIS
857
- uname [OPTION]...
858
-
859
- OPTIONS
860
- -a print all information
861
- -r print kernel release
862
- -m print machine hardware name`,uniq:`UNIQ(1) User Commands UNIQ(1)
863
-
864
- NAME
865
- uniq - report or omit repeated lines
866
-
867
- SYNOPSIS
868
- uniq [OPTION]... [INPUT [OUTPUT]]
869
-
870
- OPTIONS
871
- -c prefix lines by the number of occurrences
872
- -d only print duplicate lines
873
- -u only print unique lines`,unset:`UNSET(1) Shell Builtins UNSET(1)
874
-
875
- NAME
876
- unset - unset values and attributes of shell variables
877
-
878
- SYNOPSIS
879
- unset NAME...
880
-
881
- DESCRIPTION
882
- Remove one or more shell variables from the current environment.`,uptime:`UPTIME(1) User Commands UPTIME(1)
883
-
884
- NAME
885
- uptime - tell how long the system has been running
886
-
887
- SYNOPSIS
888
- uptime [OPTION]
889
-
890
- OPTIONS
891
- -p show uptime in a pretty format
892
- -s show system up since time`,wc:`WC(1) User Commands WC(1)
893
-
894
- NAME
895
- wc - print newline, word, and byte counts for each file
896
-
897
- SYNOPSIS
898
- wc [OPTION]... [FILE]...
899
-
900
- OPTIONS
901
- -l print the newline counts
902
- -w print the word counts
903
- -c print the byte counts`,wget:`WGET(1) User Commands WGET(1)
904
-
905
- NAME
906
- wget - non-interactive network downloader
907
-
908
- SYNOPSIS
909
- wget [OPTION]... [URL]...
910
-
911
- OPTIONS
912
- -O FILE write documents to FILE
913
- -P DIR save files to DIR
914
- -q quiet mode`,which:`WHICH(1) User Commands WHICH(1)
915
-
916
- NAME
917
- which - locate a command
918
-
919
- SYNOPSIS
920
- which COMMAND...
921
-
922
- DESCRIPTION
923
- Print the path of COMMAND found in $PATH.`,whoami:`WHOAMI(1) User Commands WHOAMI(1)
924
-
925
- NAME
926
- whoami - print effective user name
927
-
928
- SYNOPSIS
929
- whoami
930
-
931
- DESCRIPTION
932
- Print the user name associated with the current effective user ID.`,xargs:`XARGS(1) User Commands XARGS(1)
933
-
934
- NAME
935
- xargs - build and execute command lines from standard input
936
-
937
- SYNOPSIS
938
- xargs [COMMAND [INITIAL-ARGS]]
939
-
940
- DESCRIPTION
941
- Read items from stdin and execute COMMAND with those items as arguments.`};var nm={gunzip:"gzip"},Gl={name:"man",description:"Interface to the system reference manuals",category:"shell",params:["<command>"],run:async({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=e.toLowerCase(),i=nm[s]??s,o=Yl[i]??null;return o?{stdout:o,exitCode:0}:{stderr:`No manual entry for ${e}`,exitCode:16}}};var jl={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=de(e,i);$e(n,o,"mkdir"),t.vfs.mkdir(o)}return{exitCode:0}}};var Xl={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(l=>!l.startsWith("-")),[i,o]=s;if(!i||!o)return{stderr:"mv: missing operand",exitCode:1};let a=de(e,i),c=de(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 l=t.vfs.exists(c)&&t.vfs.stat(c).type==="directory"?`${c}/${i.split("/").pop()}`:c;return t.vfs.move(a,l),{exitCode:0}}catch(l){return{stderr:`mv: ${l instanceof Error?l.message:String(l)}`,exitCode:1}}}};var Jl=Wt(require("node:path"),1);var Zl={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=de(e,s);$e(n,i,"nano");let o=t.vfs.exists(i)?t.vfs.readFile(i):"",a=Jl.posix.basename(i)||"buffer",c=`/tmp/sshmimic-nano-${Date.now()}-${a}.tmp`;return{openEditor:{targetPath:i,tempPath:c,initialContent:o},exitCode:0}}};var Un=require("node:fs"),Ft=Wt(require("node:os"),1),af=Wt(require("node:path"),1);function rm(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 ef(n){return`\x1B[${n}m \x1B[0m`}function im(){let n=[40,41,42,43,44,45,46,47].map(ef).join(""),t=[100,101,102,103,104,105,106,107].map(ef).join("");return[n,t]}function tf(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 sm(n){if(n.trim().length===0)return n;let t=n.indexOf(":");if(t===-1)return n.includes("@")?nf(n):n;let e=n.substring(0,t+1),r=n.substring(t+1);return nf(e)+r}function nf(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),l=Math.round(r.g+(s.g-r.g)*a),f=Math.round(r.b+(s.b-r.b)*a);i+=`\x1B[38;2;${c};${l};${f}m${e[o]}\x1B[0m`}return i}function rf(n){return Math.max(0,Math.round(n/(1024*1024)))}function sf(){try{let n=(0,Un.readFileSync)("/etc/os-release","utf8");for(let t of n.split(`
942
- `)){if(!t.startsWith("PRETTY_NAME="))continue;return t.slice(12).trim().replace(/^"|"$/g,"")}}catch{return}}function of(n){try{let t=(0,Un.readFileSync)(n,"utf8").split(`
943
- `)[0]?.trim();return!t||t.length===0?void 0:t}catch{return}}function om(n){let t=of("/sys/devices/virtual/dmi/id/sys_vendor"),e=of("/sys/devices/virtual/dmi/id/product_name");return t&&e?`${t} ${e}`:e||n}function am(){let n=["/var/lib/dpkg/status","/usr/local/var/lib/dpkg/status"];for(let t of n)if((0,Un.existsSync)(t))try{return(0,Un.readFileSync)(t,"utf8").match(/^Package:\s+/gm)?.length??0}catch{}}function cm(){let n=["/snap","/var/lib/snapd/snaps"];for(let t of n)if((0,Un.existsSync)(t))try{return(0,Un.readdirSync)(t,{withFileTypes:!0}).filter(s=>s.isDirectory()).length}catch{}}function lm(){let n=am(),t=cm();return n!==void 0&&t!==void 0?`${n} (dpkg), ${t} (snap)`:n!==void 0?`${n} (dpkg)`:t!==void 0?`${t} (snap)`:"n/a"}function fm(){let n=Ft.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 um(n){return!n||n.trim().length===0?"unknown":af.posix.basename(n.trim())}function dm(n){let t=Ft.totalmem(),e=Ft.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??`${sf()??Ft.type()} ${Ft.arch()}`,kernel:s?.kernel??n.kernel??Ft.release(),uptimeSeconds:n.uptimeSeconds??Ft.uptime(),packages:n.packages??lm(),shell:um(n.shell),shellProps:n.shellProps??{kernel:n.kernel??Ft.release(),os:n.osName??`${sf()??Ft.type()} ${Ft.arch()}`,arch:Ft.arch()},resolution:n.resolution??"n/a (ssh)",terminal:n.terminal??"unknown",cpu:n.cpu??fm(),gpu:n.gpu??"n/a",memoryUsedMiB:n.memoryUsedMiB??rf(r),memoryTotalMiB:n.memoryTotalMiB??rf(t)}}function cf(n){let t=dm(n),e=rm(t.uptimeSeconds),r=im(),s=[" .. .:. "," .::.. .. .. ",". .... ... .. ",": .... .:. .. ",": .:.:........:. .. ",": .. ",". : ",". : ",".. : "," :. .. "," .. .. "," :-. :: "," .:. :. "," ..: ... "," ..: :.. "," :... :...."," .. ...."," . .. "," .:. .: "," :. .. "," ::. .. ","..... ..:... ","...:. .. ",".:...:. ::. .. "," ... ..:::::.. ..:::::::.. "],i=[`${t.user}@${t.host}`,"-------------------------",`OS: ${t.osName}`,`Host: ${om(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 l=s[c]??"",f=i[c]??"";if(f.length>0){let u=tf(l.padEnd(31," "),c,s.length),h=sm(f);a.push(`${u} ${h}`);continue}a.push(tf(l,c,s.length))}return a.join(`
944
- `)}var lf={name:"neofetch",description:"System info display",category:"system",params:["[--off]"],run:({args:n,authUser:t,hostname:e,shell:r,env:s})=>r.packageManager.isInstalled("neofetch")?se(n,"--help")?{stdout:"Usage: neofetch [--off]",exitCode:0}:se(n,"--off")?{stdout:`${t}@${e}`,exitCode:0}:{stdout:cf({user:t,host:e,shell:s.vars.SHELL,shellProps:r.properties,terminal:s.vars.TERM,uptimeSeconds:Math.floor((Date.now()-r.startTime)/1e3),packages:`${r.packageManager?.installedCount()??0} (dpkg)`}),exitCode:0}:{stderr:`bash: neofetch: command not found
945
- Hint: install it with: apt install neofetch
946
- `,exitCode:127}};var ko=Wt(require("node:vm"),1);var hs="v18.19.0",ff={node:hs,npm:"9.2.0",v8:"10.2.154.26-node.22"};function hm(n,t){let e={version:hs,versions:ff,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 ps(i)},cwd:()=>"/root",hrtime:()=>[0,0]},r={log:(...i)=>n.push(i.map(Nn).join(" ")),error:(...i)=>t.push(i.map(Nn).join(" ")),warn:(...i)=>t.push(i.map(Nn).join(" ")),info:(...i)=>n.push(i.map(Nn).join(" ")),dir:i=>n.push(Nn(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:`
947
- `};case"util":return{format:(...o)=>o.map(Nn).join(" "),inspect:o=>Nn(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={},ko.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 ps=class{constructor(t){this.code=t}code};function Nn(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(Nn).join(", ")} ]`;if(n instanceof Error)return`${n.name}: ${n.message}`;if(typeof n=="object")try{return`{ ${Object.entries(n).map(([e,r])=>`${e}: ${Nn(r)}`).join(", ")} }`}catch{return"[Object]"}return String(n)}function ms(n){let t=[],e=[],r=hm(t,e),s=0;try{let i=ko.default.runInContext(n,r,{timeout:5e3});i!==void 0&&t.length===0&&t.push(Nn(i))}catch(i){i instanceof ps?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(`
948
- `)}
949
- `:"",stderr:e.length?`${e.join(`
950
- `)}
951
- `:"",exitCode:s}}function pm(n){let t=n.trim();return!t.includes(`
952
- `)&&!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("//")?ms(t):ms(`(async () => { ${n} })()`)}var uf={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
953
- Hint: install it with: apt install nodejs
954
- `,exitCode:127};if(se(n,["--version","-v"]))return{stdout:`${hs}
955
- `,exitCode:0};if(se(n,["--versions"]))return{stdout:`${JSON.stringify(ff,null,2)}
956
- `,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
957
- `,exitCode:1};let{stdout:a,stderr:c,exitCode:l}=ms(o);return{stdout:a||void 0,stderr:c||void 0,exitCode:l}}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
958
- `,exitCode:1};let{stdout:a,stderr:c,exitCode:l}=ms(o);return{stdout:a||(l===0?`
959
- `:void 0),stderr:c||void 0,exitCode:l}}let i=n.find(o=>!o.startsWith("-"));if(i){let o=de(e,i);if(!t.vfs.exists(o))return{stderr:`node: cannot open file '${i}': No such file or directory
960
- `,exitCode:1};let a=t.vfs.readFile(o),{stdout:c,stderr:l,exitCode:f}=pm(a);return{stdout:c||void 0,stderr:l||void 0,exitCode:f}}return{stdout:[`Welcome to Node.js ${hs}.`,'Type ".exit" to exit the REPL.',"> "].join(`
961
- `),exitCode:0}}};var gs="9.2.0",mm="18.19.0",df={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
962
- Hint: install it with: apt install npm
963
- `,exitCode:127};if(se(n,["--version","-v"]))return{stdout:`${gs}
964
- `,exitCode:0};let e=n[0]?.toLowerCase();switch(e){case"version":case"-version":return{stdout:`{ npm: '${gs}', node: '${mm}', v8: '10.2.154.26' }
965
- `,exitCode:0};case"install":case"i":case"add":return{stderr:`npm warn: package installation is not available in the virtual runtime.
966
- npm warn: This environment simulates npm CLI behaviour only.
967
- `,exitCode:1};case"run":case"exec":case"x":return{stderr:`npm error: script execution is not available in the virtual runtime.
968
- `,exitCode:1};case"init":return{stdout:`Wrote to /home/user/package.json
969
- `,exitCode:0};case"list":case"ls":return{stdout:`${e==="ls"||e==="list"?"virtual-env@1.0.0":""}
970
- \u2514\u2500\u2500 (empty)
971
- `,exitCode:0};case"help":case void 0:return{stdout:`${[`npm ${gs}`,"","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(`
972
- `)}
973
- `,exitCode:0};default:return{stderr:`npm error: unknown command: ${e}
974
- `,exitCode:1}}}},hf={name:"npx",description:"Node.js package runner (virtual)",category:"system",params:["<package> [args]"],run:({args:n,shell:t})=>t.packageManager.isInstalled("npm")?se(n,["--version"])?{stdout:`${gs}
975
- `,exitCode:0}:{stderr:`npx: package execution is not available in the virtual runtime.
976
- `,exitCode:1}:{stderr:`bash: npx: command not found
977
- Hint: install it with: apt install npm
978
- `,exitCode:127}};var pf={name:"passwd",description:"Change user password",category:"users",params:["[username]"],run:async({authUser:n,args:t,shell:e,stdin:r})=>{let s=t[0]??n;if(n!=="root"&&n!==s)return{stderr:"passwd: permission denied",exitCode:1};if(!e.users.listUsers().includes(s))return{stderr:`passwd: user '${s}' does not exist`,exitCode:1};if(r!==void 0&&r.trim().length>0){let i=r.trim().split(`
979
- `)[0];return await e.users.setPassword(s,i),{stdout:`passwd: password updated successfully
980
- `,exitCode:0}}return{passwordChallenge:{prompt:"New password: ",confirmPrompt:"Retype new password: ",action:"passwd",targetUsername:s},exitCode:0}}};var mf={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(`
981
- `),exitCode:0}}};function gm(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+=`
982
- `,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,o=!1;n[i]==="-"&&(o=!0,i++);let a=!1;n[i]==="0"&&(a=!0,i++);let c=0;for(;i<n.length&&/\d/.test(n[i]);)c=c*10+parseInt(n[i],10),i++;let l=-1;if(n[i]===".")for(i++,l=0;i<n.length&&/\d/.test(n[i]);)l=l*10+parseInt(n[i],10),i++;let f=n[i],u=t[e++]??"",h=(p,A=" ")=>{if(c<=0||p.length>=c)return p;let y=A.repeat(c-p.length);return o?p+y:y+p};switch(f){case"s":{let p=String(u);l>=0&&(p=p.slice(0,l)),r+=h(p);break}case"d":case"i":r+=h(String(parseInt(u,10)||0),a?"0":" ");break;case"f":{let p=l>=0?l:6;r+=h((parseFloat(u)||0).toFixed(p));break}case"o":r+=h((parseInt(u,10)||0).toString(8),a?"0":" ");break;case"x":r+=h((parseInt(u,10)||0).toString(16),a?"0":" ");break;case"X":r+=h((parseInt(u,10)||0).toString(16).toUpperCase(),a?"0":" ");break;case"%":r+="%",e--;break;default:r+=n[s],s++;continue}s=i+1;continue}r+=n[s],s++}return r}var gf={name:"printf",description:"Format and print data",category:"shell",params:["<format> [args...]"],run:({args:n})=>{let t=n[0];return t?{stdout:gm(t,n.slice(1)),exitCode:0}:{stderr:"printf: missing format string",exitCode:1}}};var Af={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=se(e,["-u"])||e.includes("u")||e.includes("aux")||e.includes("au"),i=se(e,["-a","-x"])||e.includes("a")||e.includes("aux");if(s){let f=["USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND"],u=1e3;for(let h of r){let p=h.username.padEnd(10).slice(0,10),A=(Math.random()*.5).toFixed(1),y=Math.floor(Math.random()*2e4+5e3),b=Math.floor(Math.random()*5e3+1e3);f.push(`${p} ${String(u).padStart(6)} 0.0 ${A.padStart(4)} ${String(y).padStart(6)} ${String(b).padStart(5)} ${h.tty.padEnd(8)} Ss 00:00 0:00 bash`),u++}return f.push(`root ${String(u).padStart(6)} 0.0 0.0 0 0 ? S 00:00 0:00 ps`),{stdout:f.join(`
983
- `),exitCode:0}}let a=[" PID TTY TIME CMD"],c=1e3;for(let l of r)!i&&l.username!==n||(a.push(`${String(c).padStart(5)} ${l.tty.padEnd(12)} 00:00:00 ${l.username===n?"bash":`bash (${l.username})`}`),c++);return a.push(`${String(c).padStart(5)} pts/0 00:00:00 ps`),{stdout:a.join(`
984
- `),exitCode:0}}};var Ef={name:"pwd",description:"Print working directory",category:"navigation",params:[],run:({cwd:n})=>({stdout:n,exitCode:0})};var Am="Python 3.11.2";var As="3.11.2 (default, Mar 13 2023, 12:18:29) [GCC 12.2.0]",z={__pytype__:"none"};function _t(n=[]){return{__pytype__:"dict",data:new Map(n)}}function No(n,t,e=1){return{__pytype__:"range",start:n,stop:t,step:e}}function At(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="dict"}function Tr(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="range"}function Bn(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="func"}function Bo(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="class"}function pi(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="instance"}function $n(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="none"}function Tt(n){return n===null||$n(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(Tt).join(", ")}]`:At(n)?`{${[...n.data.entries()].map(([t,e])=>`'${t}': ${Tt(e)}`).join(", ")}}`:Tr(n)?`range(${n.start}, ${n.stop}${n.step!==1?`, ${n.step}`:""})`:Bn(n)?`<function ${n.name} at 0x...>`:Bo(n)?`<class '${n.name}'>`:pi(n)?`<${n.cls.name} object at 0x...>`:String(n)}function Be(n){return n===null||$n(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(Tt).join(", ")}]`:At(n)?`{${[...n.data.entries()].map(([t,e])=>`'${t}': ${Tt(e)}`).join(", ")}}`:Tr(n)?`range(${n.start}, ${n.stop}${n.step!==1?`, ${n.step}`:""})`:Tt(n)}function un(n){return n===null||$n(n)?!1:typeof n=="boolean"?n:typeof n=="number"?n!==0:typeof n=="string"||Array.isArray(n)?n.length>0:At(n)?n.data.size>0:Tr(n)?_f(n)>0:!0}function _f(n){if(n.step===0)return 0;let t=Math.ceil((n.stop-n.start)/n.step);return Math.max(0,t)}function Em(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 Pt(n){if(Array.isArray(n))return n;if(typeof n=="string")return[...n];if(Tr(n))return Em(n);if(At(n))return[...n.data.keys()];throw new yt("TypeError",`'${ur(n)}' object is not iterable`)}function ur(n){return n===null||$n(n)?"NoneType":typeof n=="boolean"?"bool":typeof n=="number"?Number.isInteger(n)?"int":"float":typeof n=="string"?"str":Array.isArray(n)?"list":At(n)?"dict":Tr(n)?"range":Bn(n)?"function":Bo(n)?"type":pi(n)?n.cls.name:"object"}var yt=class{constructor(t,e){this.type=t;this.message=e}type;message;toString(){return`${this.type}: ${this.message}`}},Pr=class{constructor(t){this.value=t}value},mi=class{},gi=class{},Ai=class{constructor(t){this.code=t}code};function ym(n){let t=new Map,e=_t([["sep","/"],["linesep",`
985
- `],["curdir","."],["pardir",".."]]);return e.__methods__={getcwd:()=>n,getenv:r=>typeof r=="string"?process.env[r]??z:z,path:_t([["join",z],["exists",z],["dirname",z],["basename",z]]),listdir:()=>[]},t.set("__builtins__",z),t.set("__name__","__main__"),t.set("__cwd__",n),t}function _m(n){let t=_t([["sep","/"],["curdir","."]]),e=_t([["sep","/"],["linesep",`
986
- `],["name","posix"]]);return e._cwd=n,t._cwd=n,e.path=t,e}function Sm(){return _t([["version",As],["version_info",_t([["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 bm(){return _t([["pi",Math.PI],["e",Math.E],["tau",Math.PI*2],["inf",1/0],["nan",NaN],["sqrt",z],["floor",z],["ceil",z],["log",z],["pow",z],["sin",z],["cos",z],["tan",z],["fabs",z],["factorial",z]])}function xm(){return _t([["dumps",z],["loads",z]])}function wm(){return _t([["match",z],["search",z],["findall",z],["sub",z],["split",z],["compile",z]])}var yf={os:_m,sys:()=>Sm(),math:()=>bm(),json:()=>xm(),re:()=>wm(),random:()=>_t([["random",z],["randint",z],["choice",z],["shuffle",z]]),time:()=>_t([["time",z],["sleep",z],["ctime",z]]),datetime:()=>_t([["datetime",z],["date",z],["timedelta",z]]),collections:()=>_t([["Counter",z],["defaultdict",z],["OrderedDict",z]]),itertools:()=>_t([["chain",z],["product",z],["combinations",z],["permutations",z]]),functools:()=>_t([["reduce",z],["partial",z],["lru_cache",z]]),string:()=>_t([["ascii_letters","abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"],["digits","0123456789"],["punctuation","!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"]])},Es=class{constructor(t){this.cwd=t}cwd;output=[];stderr=[];modules=new Map;getOutput(){return this.output.join(`
987
- `)+(this.output.length?`
988
- `:"")}getStderr(){return this.stderr.join(`
989
- `)+(this.stderr.length?`
990
- `:"")}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 z;if(t==="True")return!0;if(t==="False")return!1;if(t==="...")return z;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,`
991
- `).replace(/\\t/g," ").replace(/\\r/g,"\r").replace(/\\\\/g,"\\").replace(/\\'/g,"'").replace(/\\"/g,'"');let r=t.match(/^f(['"])([\s\S]*)\1$/);if(r){let l=r[2];return l=l.replace(/\{([^{}]+)\}/g,(f,u)=>{try{return Be(this.pyEval(u.trim(),e))}catch{return`{${u}}`}}),l}let s=t.match(/^b(['"])(.*)\1$/s);if(s)return s[2];if(t.startsWith("[")&&t.endsWith("]")){let l=t.slice(1,-1).trim();if(!l)return[];let f=l.match(/^(.+?)\s+for\s+(\w+)\s+in\s+(.+?)(?:\s+if\s+(.+))?$/);if(f){let[,u,h,p,A]=f,y=Pt(this.pyEval(p.trim(),e)),b=[];for(let x of y){let B=new Map(e);B.set(h,x),!(A&&!un(this.pyEval(A,B)))&&b.push(this.pyEval(u.trim(),B))}return b}return this.splitArgs(l).map(u=>this.pyEval(u,e))}if(t.startsWith("(")&&t.endsWith(")")){let l=t.slice(1,-1).trim();if(!l)return[];let f=this.splitArgs(l);return f.length===1&&!l.endsWith(",")?this.pyEval(f[0],e):f.map(u=>this.pyEval(u,e))}if(t.startsWith("{")&&t.endsWith("}")){let l=t.slice(1,-1).trim();if(!l)return _t();let f=_t();for(let u of this.splitArgs(l)){let h=u.indexOf(":");if(h===-1)continue;let p=Be(this.pyEval(u.slice(0,h).trim(),e)),A=this.pyEval(u.slice(h+1).trim(),e);f.data.set(p,A)}return f}let i=t.match(/^not\s+(.+)$/);if(i)return!un(this.pyEval(i[1],e));let o=[["or"],["and"],["in","not in","is not","is","==","!=","<=",">=","<",">"],["+","-"],["**"],["*","//","/","%"]];for(let l of o){let f=this.tryBinaryOp(t,l,e);if(f!==void 0)return f}if(t.startsWith("-")){let l=this.pyEval(t.slice(1),e);if(typeof l=="number")return-l}if(process.env.PY_DEBUG&&console.error("eval:",JSON.stringify(t)),t.endsWith("]")&&!t.startsWith("[")){let l=this.findMatchingBracket(t,"[");if(l!==-1){let f=this.pyEval(t.slice(0,l),e),u=t.slice(l+1,-1);return this.subscript(f,u,e)}}let a=t.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*\(([\s\S]*)\)$/);if(a){let[,l,f]=a,u=(f?.trim()?this.splitArgs(f):[]).map(h=>this.pyEval(h,e));return this.callBuiltin(l,u,e)}let c=this.findDotAccess(t);if(c){let{objExpr:l,attr:f,callPart:u}=c,h=this.pyEval(l,e);if(u!==void 0){let p=u.slice(1,-1),A=p.trim()?this.splitArgs(p).map(y=>this.pyEval(y,e)):[];return this.callMethod(h,f,A,e)}return this.getAttr(h,f,e)}if(/^[A-Za-z_][A-Za-z0-9_]*$/.test(t)){if(e.has(t))return e.get(t);throw new yt("NameError",`name '${t}' is not defined`)}if(/^[A-Za-z_][A-Za-z0-9_.]+$/.test(t)){let l=t.split("."),f=e.get(l[0])??(()=>{throw new yt("NameError",`name '${l[0]}' is not defined`)})();for(let u of l.slice(1))f=this.getAttr(f,u,e);return f}return z}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(),l=t.slice(i+1).match(/^(\w+)(\([\s\S]*\))?$/);if(l&&!/^-?\d+$/.test(a))return{objExpr:a,attr:l[1],callPart:l[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 l of e)if(t.slice(a,a+l.length)===l){if(l==="*"&&(t[a+1]==="*"||t[a-1]==="*"))continue;let f=t[a-1],u=t[a+l.length];if(/^[a-z]/.test(l)&&(f&&/\w/.test(f)||u&&/\w/.test(u)))continue;let p=t.slice(0,a).trim(),A=t.slice(a+l.length).trim();if(!p||!A)continue;return this.applyBinaryOp(l,p,A,r)}}}}applyBinaryOp(t,e,r,s){if(t==="and"){let a=this.pyEval(e,s);return un(a)?this.pyEval(r,s):a}if(t==="or"){let a=this.pyEval(e,s);return un(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 yt("ZeroDivisionError","division by zero");return i/o}case"//":{if(o===0)throw new yt("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 yt("ZeroDivisionError","integer division or modulo by zero");return i%o}case"**":return i**o;case"==":return Tt(i)===Tt(o)||i===o;case"!=":return Tt(i)!==Tt(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||$n(i)&&$n(o);case"is not":return!(i===o||$n(i)&&$n(o))}return z}pyIn(t,e){return typeof t=="string"?typeof e=="string"&&t.includes(e):Array.isArray(t)?t.some(r=>Tt(r)===Tt(e)):At(t)?t.data.has(Be(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):z}let s=this.pyEval(e,r);if(Array.isArray(t)){let i=s;return i<0&&(i=t.length+i),t[i]??z}if(typeof t=="string"){let i=s;return i<0&&(i=t.length+i),t[i]??z}if(At(t))return t.data.get(Be(s))??z;throw new yt("TypeError",`'${ur(t)}' is not subscriptable`)}getAttr(t,e,r){return At(t)?t.data.has(e)?t.data.get(e):e==="path"&&t.path?t.path:z:pi(t)?t.attrs.get(e)??z:typeof t=="string"?{__class__:{__pytype__:"class",name:"str"}}[e]??z:z}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(`
992
- `);case"join":return Pt(r[0]??[]).map(Be).join(t);case"replace":return t.replaceAll(Be(r[0]??""),Be(r[1]??""));case"startswith":return t.startsWith(Be(r[0]??""));case"endswith":return t.endsWith(Be(r[0]??""));case"find":return t.indexOf(Be(r[0]??""));case"index":{let i=t.indexOf(Be(r[0]??""));if(i===-1)throw new yt("ValueError","substring not found");return i}case"count":return t.split(Be(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=Be(r[1]??" ");return t.padStart(Math.floor((i+t.length)/2),o).padEnd(i,o)}case"ljust":return t.padEnd(r[0]??0,Be(r[1]??" "));case"rjust":return t.padStart(r[0]??0,Be(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]??z),z;case"extend":for(let i of Pt(r[0]??[]))t.push(i);return z;case"insert":return t.splice(r[0]??0,0,r[1]??z),z;case"pop":{let i=r[0]!==void 0?r[0]:-1,o=i<0?t.length+i:i;return t.splice(o,1)[0]??z}case"remove":{let i=t.findIndex(o=>Tt(o)===Tt(r[0]??z));return i!==-1&&t.splice(i,1),z}case"index":{let i=t.findIndex(o=>Tt(o)===Tt(r[0]??z));if(i===-1)throw new yt("ValueError","is not in list");return i}case"count":return t.filter(i=>Tt(i)===Tt(r[0]??z)).length;case"sort":return t.sort((i,o)=>typeof i=="number"&&typeof o=="number"?i-o:Be(i).localeCompare(Be(o))),z;case"reverse":return t.reverse(),z;case"copy":return[...t];case"clear":return t.splice(0),z}if(At(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(Be(r[0]??""))??r[1]??z;case"update":{if(At(r[0]??z))for(let[i,o]of r[0].data)t.data.set(i,o);return z}case"pop":{let i=Be(r[0]??""),o=t.data.get(i)??r[1]??z;return t.data.delete(i),o}case"clear":return t.data.clear(),z;case"copy":return _t([...t.data.entries()]);case"setdefault":{let i=Be(r[0]??"");return t.data.has(i)||t.data.set(i,r[1]??z),t.data.get(i)??z}}if(At(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]??z:z;case"listdir":return[];case"path":return t}if(At(t))switch(e){case"join":return r.map(Be).join("/").replace(/\/+/g,"/");case"exists":return!1;case"dirname":return Be(r[0]??"").split("/").slice(0,-1).join("/")||"/";case"basename":return Be(r[0]??"").split("/").pop()??"";case"abspath":return Be(r[0]??"");case"splitext":{let i=Be(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(At(t)&&t.data.has("version")&&t.data.get("version")===As&&e==="exit")throw new Ai(r[0]??0);if(At(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(At(t)){if(e==="dumps"){let i=At(r[1]??z)?r[1]:void 0,o=i?i.data.get("indent"):void 0;return JSON.stringify(this.pyToJs(r[0]??z),null,o)}if(e==="loads")return this.jsToPy(JSON.parse(Be(r[0]??"")))}if(pi(t)){let i=t.attrs.get(e)??t.cls.methods.get(e)??z;if(Bn(i)){let o=new Map(i.closure);return o.set("self",t),i.params.slice(1).forEach((a,c)=>o.set(a,r[c]??z)),this.execBlock(i.body,o)}}throw new yt("AttributeError",`'${ur(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 Be(o??z);case"r":return Tt(o??z);default:return String(o)}})}pyToJs(t){return $n(t)?null:At(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?z:typeof t=="boolean"||typeof t=="number"||typeof t=="string"?t:Array.isArray(t)?t.map(e=>this.jsToPy(e)):typeof t=="object"?_t(Object.entries(t).map(([e,r])=>[e,this.jsToPy(r)])):z}callBuiltin(t,e,r){if(r.has(t)){let s=r.get(t)??z;return Bn(s)?this.callFunc(s,e,r):Bo(s)?this.instantiate(s,e,r):s}switch(t){case"print":return this.output.push(e.map(Be).join(" ")+`
993
- `.replace(/\\n/g,"")),z;case"input":return this.output.push(Be(e[0]??"")),"";case"int":{if(e.length===0)return 0;let s=e[1]??10,i=parseInt(Be(e[0]??0),s);return Number.isNaN(i)?(()=>{throw new yt("ValueError","invalid literal for int()")})():i}case"float":{if(e.length===0)return 0;let s=parseFloat(Be(e[0]??0));return Number.isNaN(s)?(()=>{throw new yt("ValueError","could not convert to float")})():s}case"str":return e.length===0?"":Be(e[0]??z);case"bool":return e.length===0?!1:un(e[0]??z);case"list":return e.length===0?[]:Pt(e[0]??[]);case"tuple":return e.length===0?[]:Pt(e[0]??[]);case"set":return e.length===0?[]:[...new Set(Pt(e[0]??[]).map(Tt))].map(s=>Pt(e[0]??[]).find(o=>Tt(o)===s)??z);case"dict":return e.length===0?_t():At(e[0]??z)?e[0]:_t();case"bytes":return typeof e[0]=="string"?e[0]:Be(e[0]??"");case"bytearray":return e.length===0?"":Be(e[0]??"");case"type":return e.length===1?`<class '${ur(e[0]??z)}'>`:z;case"isinstance":return ur(e[0]??z)===Be(e[1]??"");case"issubclass":return!1;case"callable":return Bn(e[0]??z);case"hasattr":return At(e[0]??z)?e[0].data.has(Be(e[1]??"")):!1;case"getattr":return At(e[0]??z)?e[0].data.get(Be(e[1]??""))??e[2]??z:e[2]??z;case"setattr":return At(e[0]??z)&&e[0].data.set(Be(e[1]??""),e[2]??z),z;case"len":{let s=e[0]??z;if(typeof s=="string"||Array.isArray(s))return s.length;if(At(s))return s.data.size;if(Tr(s))return _f(s);throw new yt("TypeError",`object of type '${ur(s)}' has no len()`)}case"range":return e.length===1?No(0,e[0]):e.length===2?No(e[0],e[1]):No(e[0],e[1],e[2]);case"enumerate":{let s=e[1]??0;return Pt(e[0]??[]).map((i,o)=>[o+s,i])}case"zip":{let s=e.map(Pt),i=Math.min(...s.map(o=>o.length));return Array.from({length:i},(o,a)=>s.map(c=>c[a]??z))}case"map":{let s=e[0]??z;return Pt(e[1]??[]).map(i=>Bn(s)?this.callFunc(s,[i],r):z)}case"filter":{let s=e[0]??z;return Pt(e[1]??[]).filter(i=>Bn(s)?un(this.callFunc(s,[i],r)):un(i))}case"reduce":{let s=e[0]??z,i=Pt(e[1]??[]);if(i.length===0)return e[2]??z;let o=e[2]!==void 0?e[2]:i[0];for(let a of e[2]!==void 0?i:i.slice(1))o=Bn(s)?this.callFunc(s,[o,a],r):z;return o}case"sorted":{let s=[...Pt(e[0]??[])],i=e[1]??z,o=At(i)?i.data.get("key")??z:i;return s.sort((a,c)=>{let l=Bn(o)?this.callFunc(o,[a],r):a,f=Bn(o)?this.callFunc(o,[c],r):c;return typeof l=="number"&&typeof f=="number"?l-f:Be(l).localeCompare(Be(f))}),s}case"reversed":return[...Pt(e[0]??[])].reverse();case"any":return Pt(e[0]??[]).some(un);case"all":return Pt(e[0]??[]).every(un);case"sum":return Pt(e[0]??[]).reduce((s,i)=>s+i,e[1]??0);case"max":return(e.length===1?Pt(e[0]??[]):e).reduce((i,o)=>i>=o?i:o);case"min":return(e.length===1?Pt(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 Be(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]:Be(e[0]??"").split("").reduce((s,i)=>s*31+i.charCodeAt(0)|0,0);case"open":throw new yt("PermissionError","open() not available in virtual runtime");case"repr":return Tt(e[0]??z);case"iter":return e[0]??z;case"next":return Array.isArray(e[0])&&e[0].length>0?e[0].shift():e[1]??(()=>{throw new yt("StopIteration","")})();case"vars":return _t([...r.entries()].map(([s,i])=>[s,i]));case"globals":return _t([...r.entries()].map(([s,i])=>[s,i]));case"locals":return _t([...r.entries()].map(([s,i])=>[s,i]));case"dir":{if(e.length===0)return[...r.keys()];let s=e[0]??z;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"]:At(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 yt(t,Be(e[0]??""));case"exec":return this.execScript(Be(e[0]??""),r),z;case"eval":return this.pyEval(Be(e[0]??""),r);default:throw new yt("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]??z)});try{return this.execBlock(t.body,s)}catch(i){if(i instanceof Pr)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(`
994
- `);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 Pr)return r.value;throw r}return z}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 mi;if(i==="continue")throw new gi;let a=i.match(/^return(?:\s+(.+))?$/);if(a)throw new Pr(a[1]?this.pyEval(a[1],r):z);let c=i.match(/^raise(?:\s+(.+))?$/);if(c){if(c[1]){let N=this.pyEval(c[1],r);throw new yt(typeof N=="string"?N:ur(N),Be(N))}throw new yt("RuntimeError","")}let l=i.match(/^assert\s+(.+?)(?:,\s*(.+))?$/);if(l){if(!un(this.pyEval(l[1],r)))throw new yt("AssertionError",l[2]?Be(this.pyEval(l[2],r)):"");return e+1}let f=i.match(/^del\s+(.+)$/);if(f)return r.delete(f[1].trim()),e+1;let u=i.match(/^import\s+(\w+)(?:\s+as\s+(\w+))?$/);if(u){let[,N,S]=u,w=yf[N];if(w){let v=w(this.cwd);this.modules.set(N,v),r.set(S??N,v)}return e+1}let h=i.match(/^from\s+(\w+)\s+import\s+(.+)$/);if(h){let[,N,S]=h,w=yf[N];if(w){let v=w(this.cwd);if(S?.trim()==="*")for(let[k,P]of v.data)r.set(k,P);else for(let k of S.split(",").map(P=>P.trim()))r.set(k,v.data.get(k)??z)}return e+1}let p=i.match(/^def\s+(\w+)\s*\(([^)]*)\)\s*:$/);if(p){let[,N,S]=p,w=S.split(",").map(P=>P.trim()).filter(Boolean),v=this.collectBlock(t,e+1,o),k={__pytype__:"func",name:N,params:w,body:v,closure:new Map(r)};return r.set(N,k),e+1+v.length}let A=i.match(/^class\s+(\w+)(?:\(([^)]*)\))?\s*:$/);if(A){let[,N,S]=A,w=S?S.split(",").map(ne=>ne.trim()):[],v=this.collectBlock(t,e+1,o),k={__pytype__:"class",name:N,methods:new Map,bases:w},P=0;for(;P<v.length;){let Y=v[P].trim().match(/^def\s+(\w+)\s*\(([^)]*)\)\s*:$/);if(Y){let[,G,te]=Y,le=te.split(",").map(R=>R.trim()).filter(Boolean),U=this.collectBlock(v,P+1,0);k.methods.set(G,{__pytype__:"func",name:G,params:le,body:U,closure:new Map(r)}),P+=1+U.length}else P++}return r.set(N,k),e+1+v.length}if(i.startsWith("if ")&&i.endsWith(":")){let N=i.slice(3,-1).trim(),S=this.collectBlock(t,e+1,o),w=S.length+1;if(un(this.pyEval(N,r))){this.execBlock(S,new Map(r).also?.(P=>{for(let[ne,Y]of r)P.set(ne,Y)})??r),this.runBlockInScope(S,r);let k=e+1+S.length;for(;k<t.length;){let P=t[k].trim();if(this.getIndent(t[k])<o||!P.startsWith("elif")&&!P.startsWith("else"))break;let ne=this.collectBlock(t,k+1,o);k+=1+ne.length}return k}let v=e+1+S.length;for(;v<t.length;){let k=t[v],P=k.trim();if(this.getIndent(k)!==o)break;let ne=P.match(/^elif\s+(.+):$/);if(ne){let Y=this.collectBlock(t,v+1,o);if(un(this.pyEval(ne[1],r))){for(this.runBlockInScope(Y,r),v+=1+Y.length;v<t.length;){let G=t[v].trim();if(this.getIndent(t[v])!==o||!G.startsWith("elif")&&!G.startsWith("else"))break;let te=this.collectBlock(t,v+1,o);v+=1+te.length}return v}v+=1+Y.length;continue}if(P==="else:"){let Y=this.collectBlock(t,v+1,o);return this.runBlockInScope(Y,r),v+1+Y.length}break}return v}let y=i.match(/^for\s+(.+?)\s+in\s+(.+?)\s*:$/);if(y){let[,N,S]=y,w=Pt(this.pyEval(S.trim(),r)),v=this.collectBlock(t,e+1,o),k=[],P=e+1+v.length;P<t.length&&t[P]?.trim()==="else:"&&(k=this.collectBlock(t,P+1,o),P+=1+k.length);let ne=!1;for(let Y of w){if(N.includes(",")){let G=N.split(",").map(le=>le.trim()),te=Array.isArray(Y)?Y:[Y];G.forEach((le,U)=>r.set(le,te[U]??z))}else r.set(N.trim(),Y);try{this.runBlockInScope(v,r)}catch(G){if(G instanceof mi){ne=!0;break}if(G instanceof gi)continue;throw G}}return!ne&&k.length&&this.runBlockInScope(k,r),P}let b=i.match(/^while\s+(.+?)\s*:$/);if(b){let N=b[1],S=this.collectBlock(t,e+1,o),w=0;for(;un(this.pyEval(N,r))&&w++<1e5;)try{this.runBlockInScope(S,r)}catch(v){if(v instanceof mi)break;if(v instanceof gi)continue;throw v}return e+1+S.length}if(i==="try:"){let N=this.collectBlock(t,e+1,o),S=e+1+N.length,w=[],v=[],k=[];for(;S<t.length;){let ne=t[S],Y=ne.trim();if(this.getIndent(ne)!==o)break;if(Y.startsWith("except")){let G=Y.match(/^except(?:\s+(\w+)(?:\s+as\s+(\w+))?)?\s*:$/),te=G?.[1]??null,le=G?.[2],U=this.collectBlock(t,S+1,o);w.push({exc:te,body:U}),le&&r.set(le,""),S+=1+U.length}else if(Y==="else:")k=this.collectBlock(t,S+1,o),S+=1+k.length;else if(Y==="finally:")v=this.collectBlock(t,S+1,o),S+=1+v.length;else break}let P=null;try{this.runBlockInScope(N,r),k.length&&this.runBlockInScope(k,r)}catch(ne){if(ne instanceof yt){P=ne;let Y=!1;for(let G of w)if(G.exc===null||G.exc===ne.type||G.exc==="Exception"){this.runBlockInScope(G.body,r),Y=!0;break}if(!Y)throw ne}else throw ne}finally{v.length&&this.runBlockInScope(v,r)}return S}let x=i.match(/^with\s+(.+?)\s+as\s+(\w+)\s*:$/);if(x){let N=this.collectBlock(t,e+1,o);return r.set(x[2],z),this.runBlockInScope(N,r),e+1+N.length}let B=i.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*(\+=|-=|\*=|\/\/=|\/=|%=|\*\*=|&=|\|=)\s*(.+)$/);if(B){let[,N,S,w]=B,v=r.get(N)??0,k=this.pyEval(w,r),P;switch(S){case"+=":P=typeof v=="string"?v+Be(k):v+k;break;case"-=":P=v-k;break;case"*=":P=v*k;break;case"/=":P=v/k;break;case"//=":P=Math.floor(v/k);break;case"%=":P=v%k;break;case"**=":P=v**k;break;default:P=k}return r.set(N,P),e+1}let H=i.match(/^([A-Za-z_][A-Za-z0-9_]*)\[(.+)\]\s*=\s*(.+)$/);if(H){let[,N,S,w]=H,v=r.get(N)??z,k=this.pyEval(w,r)??z,P=this.pyEval(S,r)??z;return Array.isArray(v)?v[P]=k:At(v)&&v.data.set(Be(P),k),e+1}let C=i.match(/^([A-Za-z_][A-Za-z0-9_.]+)\s*=\s*(.+)$/);if(C){let N=C[1].lastIndexOf(".");if(N!==-1){let S=C[1].slice(0,N),w=C[1].slice(N+1),v=this.pyEval(C[2],r),k=this.pyEval(S,r);return At(k)?k.data.set(w,v):pi(k)&&k.attrs.set(w,v),e+1}}let M=i.match(/^([A-Za-z_][A-Za-z0-9_,\s]*),\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.+)$/);if(M){let N=this.pyEval(M[3],r),S=i.split("=")[0].split(",").map(v=>v.trim()),w=Pt(N);return S.forEach((v,k)=>r.set(v,w[k]??z)),e+1}let Q=i.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*(?::[^=]+)?\s*=\s*(.+)$/);if(Q){let[,N,S]=Q;return r.set(N,this.pyEval(S,r)),e+1}try{this.pyEval(i,r)}catch(N){if(N instanceof yt||N instanceof Ai)throw N}return e+1}runBlockInScope(t,e){this.execLines(t,0,e)}run(t){let e=ym(this.cwd);try{this.execScript(t,e)}catch(r){return r instanceof Ai?{stdout:this.getOutput(),stderr:this.getStderr(),exitCode:r.code}:r instanceof yt?(this.stderr.push(r.toString()),{stdout:this.getOutput(),stderr:this.getStderr(),exitCode:1}):r instanceof Pr?{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}}},Sf={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
995
- Hint: install it with: apt install python3
996
- `,exitCode:127};if(se(n,["--version","-V"]))return{stdout:`${Am}
997
- `,exitCode:0};if(se(n,["--version-full"]))return{stdout:`${As}
998
- `,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
999
- `,exitCode:1};let o=i.replace(/\\n/g,`
1000
- `).replace(/\\t/g," "),a=new Es(e),{stdout:c,stderr:l,exitCode:f}=a.run(o);return{stdout:c||void 0,stderr:l||void 0,exitCode:f}}let s=n.find(i=>!i.startsWith("-"));if(s){let i=de(e,s);if(!t.vfs.exists(i))return{stderr:`python3: can't open file '${s}': [Errno 2] No such file or directory
1001
- `,exitCode:2};let o=t.vfs.readFile(i),a=new Es(e),{stdout:c,stderr:l,exitCode:f}=a.run(o);return{stdout:c||void 0,stderr:l||void 0,exitCode:f}}return{stdout:`${As}
1002
- Type "help", "copyright", "credits" or "license" for more information.
1003
- >>> `,exitCode:0}}};var bf={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(`
1004
- `)[0]??"",o=se(n,["-r"])?i:i.replace(/\\(?:\r?\n|.)/g,a=>a[1]===`
1005
- `||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 xf={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=se(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=de(e,o);$e(n,a,"rm"),t.vfs.remove(a,{recursive:s})}return{exitCode:0}}};var wf={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=se(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=de(e,a);try{c=t.vfs.readFile(b)}catch{return{stderr:`sed: ${a}: No such file or directory`,exitCode:1}}}let l=o.match(/^s([^a-zA-Z0-9])(.+?)\1(.*?)\1([gi]*)$/);if(!l)return{stderr:`sed: unrecognized command: ${o}`,exitCode:1};let[,,f,u,h]=l,p=(h??"").includes("i")?"gi":(h??"").includes("g")?"g":"",A;try{A=new RegExp(f,p||"")}catch{return{stderr:`sed: invalid regex: ${f}`,exitCode:1}}let y=((h??"").includes("g")||p.includes("g"),c.replace(A,u??""));if(i&&a){let b=de(e,a);return t.writeFileAsUser(n,b,y),{exitCode:0}}return{stdout:y,exitCode:0}}};var If={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(`
1006
- `),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}}};async function Cf(n,t,e,r,s,i,o){let a={exitCode:0},c=[],l=s,f=0;for(;f<n.length;){let h=n[f];if(a=await Im(h.pipeline,t,e,r,l,i,o),o.lastExitCode=a.exitCode??0,a.nextCwd&&(a.exitCode??0)===0&&(l=a.nextCwd),a.stdout&&c.push(a.stdout),a.closeSession||a.switchUser)return{...a,stdout:c.join("")||a.stdout};let p=h.op;if(!(!p||p===";")){if(p==="&&"){if((a.exitCode??0)!==0)for(;f<n.length&&n[f]?.op==="&&";)f++}else if(p==="||"&&(a.exitCode??0)===0)for(;f<n.length&&n[f]?.op==="||";)f++}f++}let u=c.join("");return{...a,stdout:u||a.stdout,nextCwd:l!==s?l:void 0}}async function Im(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?Cm(n.commands[0],t,e,r,s,i,a):vm(n.commands,t,e,r,s,i,a)}async function Cm(n,t,e,r,s,i,o){let a;if(n.inputFile){let l=de(s,n.inputFile);try{a=i.vfs.readFile(l)}catch{return{stderr:`${n.inputFile}: No such file or directory`,exitCode:1}}}let c=await Or(n.name,n.args,t,e,r,s,i,a,o);if(n.outputFile){let l=de(s,n.outputFile),f=c.stdout||"";try{if(n.appendOutput){let u=(()=>{try{return i.vfs.readFile(l)}catch{return""}})();i.writeFileAsUser(t,l,u+f)}else i.writeFileAsUser(t,l,f);return{...c,stdout:""}}catch{return{...c,stderr:`Failed to write to ${n.outputFile}`,exitCode:1}}}return c}async function vm(n,t,e,r,s,i,o){let a="",c=0;for(let l=0;l<n.length;l++){let f=n[l];if(l===0&&f.inputFile){let h=de(s,f.inputFile);try{a=i.vfs.readFile(h)}catch{return{stderr:`${f.inputFile}: No such file or directory`,exitCode:1}}}let u=await Or(f.name,f.args,t,e,r,s,i,a,o);if(c=u.exitCode??0,l===n.length-1&&f.outputFile){let h=de(s,f.outputFile),p=u.stdout||"";try{if(f.appendOutput){let A=(()=>{try{return i.vfs.readFile(h)}catch{return""}})();i.writeFileAsUser(t,h,A+p)}else i.writeFileAsUser(t,h,p);a=""}catch{return{stderr:`Failed to write to ${f.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 Ei(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(!r&&o==="2"&&a===">"){let c=n.slice(i+1);if(c.startsWith(">>&1")||c.startsWith(">> &1")){e&&(t.push(e),e=""),t.push("2>>&1"),i+=5;continue}if(c.startsWith(">&1")){e&&(t.push(e),e=""),t.push("2>&1"),i+=4;continue}if(c.startsWith(">>")){e&&(t.push(e),e=""),t.push("2>>"),i+=3;continue}if(c.startsWith(">")){e&&(t.push(e),e=""),t.push("2>"),i+=2;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 vf(n){let t=n.trim();if(!t)return{statements:[],isValid:!0};try{return{statements:km(t),isValid:!0}}catch(e){return{statements:[],isValid:!1,error:e.message}}}function km(n){let t=Nm(n),e=[];for(let r of t){let i={pipeline:{commands:Bm(r.text.trim()),isValid:!0}};r.op&&(i.op=r.op),e.push(i)}return e}function Nm(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],l=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(l==="&&"){a("&&"),o+=2;continue}if(l==="||"){a("||"),o+=2;continue}if(c===";"){a(";"),o++;continue}e+=c,o++}return a(),t}function Bm(n){return Rm(n).map(Pm)}function Rm(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 Pm(n){let t=Ei(n);if(t.length===0)return{name:"",args:[]};let e=[],r,s,i=!1,o=0,a,c=!1,l=!1;for(;o<t.length;){let h=t[o];if(h==="<"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after <");r=t[o],o++}else if(h===">>"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after >>");s=t[o],i=!0,o++}else if(h===">"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after >");s=t[o],i=!1,o++}else if(h==="2>&1")l=!0,o++;else if(h==="2>>"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after 2>>");a=t[o],c=!0,o++}else if(h==="2>"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after 2>");a=t[o],c=!1,o++}else e.push(h),o++}let f=e[0]??"";return{name:/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/.test(f)?f:f.toLowerCase(),args:e.slice(1),inputFile:r,outputFile:s,appendOutput:i,stderrFile:a,stderrAppend:c,stderrToStdout:l}}function Lr(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 kf(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 Or(n,t,e,r,s,i,o,a,c){let l=/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/,f=[n,...t],u=0;for(;u<f.length&&l.test(f[u]);)u+=1;if(u>0){let A=f.slice(0,u).map(x=>x.match(l)),y=f.slice(u),b=[];for(let[,x,B]of A)b.push([x,c.vars[x]]),c.vars[x]=B;if(y.length===0)return{exitCode:0};try{return await Or(y[0],y.slice(1),e,r,s,i,o,a,c)}finally{for(let[x,B]of b)B===void 0?delete c.vars[x]:c.vars[x]=B}}let h=c.vars[`__alias_${n}`];if(h)return xt(`${h} ${t.join(" ")}`,e,r,s,i,o,a,c);let p=Sn(n);if(!p){let A=kf(n,c,o,e);if(A){let y=o.vfs.readFile(A),b=y.match(/exec\s+builtin\s+(\S+)/);if(b){let B=Sn(b[1]);if(B)return await B.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 x=Sn("sh");if(x)return await x.run({authUser:e,hostname:r,activeSessions:o.users.listActiveSessions(),rawInput:`sh -c ${JSON.stringify(y)}`,mode:s,args:["-c",y,"--",...t],stdin:a,cwd:i,shell:o,env:c})}return{stderr:`${n}: command not found`,exitCode:127}}try{return await p.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(A){return{stderr:A instanceof Error?A.message:"Command failed",exitCode:1}}}async function xt(n,t,e,r,s,i,o,a){let c=n.trim();if(c.length===0)return{exitCode:0};let l=a??Lr(t,e),u=Ei(c)[0]?.toLowerCase()??"",h=l.vars[`__alias_${u}`],p=h?c.replace(u,h):c,A=/\bfor\s+\w+\s+in\b/.test(p)||/\bwhile\s+/.test(p)||/\bif\s+/.test(p)||/\w+\s*\(\s*\)\s*\{/.test(p)||/\bfunction\s+\w+/.test(p)||/\(\(\s*.+\s*\)\)/.test(p),y=/(?<![|&])[|](?![|])/.test(p)||p.includes(">")||p.includes("<")||p.includes("&&")||p.includes("||")||p.includes(";");if(A&&u!=="sh"&&u!=="bash"||y){if(A&&u!=="sh"&&u!=="bash"){let N=Sn("sh");if(N)return await N.run({authUser:t,hostname:e,activeSessions:i.users.listActiveSessions(),rawInput:p,mode:r,args:["-c",p],stdin:void 0,cwd:s,shell:i,env:l})}let Q=vf(p);if(!Q.isValid)return{stderr:Q.error||"Syntax error",exitCode:1};try{return await Cf(Q.statements,t,e,r,s,i,l)}catch(N){return{stderr:N instanceof Error?N.message:"Execution failed",exitCode:1}}}let b=await fs(p,l.vars,l.lastExitCode,Q=>xt(Q,t,e,r,s,i,void 0,l).then(N=>N.stdout??"")),x=Ei(b.trim());if(x.length===0)return{exitCode:0};if(/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/.test(x[0]))return Or(x[0],x.slice(1),t,e,r,s,i,o,l);let H=x[0]?.toLowerCase()??"",C=x.slice(1).flatMap(ls),M=Sn(H);if(!M){let Q=kf(H,l,i,t);if(Q){let N=i.vfs.readFile(Q),S=N.match(/exec\s+builtin\s+(\S+)/);if(S){let v=S[1],k=Sn(v);if(k)return await k.run({authUser:t,hostname:e,activeSessions:i.users.listActiveSessions(),rawInput:[H,...C].join(" "),mode:r,args:C,stdin:o,cwd:s,shell:i,env:l})}let w=Sn("sh");if(w)return await w.run({authUser:t,hostname:e,activeSessions:i.users.listActiveSessions(),rawInput:`sh -c ${JSON.stringify(N)}`,mode:r,args:["-c",N,"--",...C],stdin:o,cwd:s,shell:i,env:l})}return{stderr:`${H}: command not found`,exitCode:127}}try{return await M.run({authUser:t,hostname:e,activeSessions:i.users.listActiveSessions(),rawInput:b,mode:r,args:C,stdin:o,cwd:s,shell:i,env:l})}catch(Q){return{stderr:Q instanceof Error?Q.message:"Command failed",exitCode:1}}}async function Po(n,t,e,r){return fs(n,t,e,s=>xt(s,r.authUser,r.hostname,r.mode,r.cwd,r.shell,void 0,r.env).then(i=>i.stdout??""))}function Yn(n){let t=[],e=0;for(;e<n.length;){let r=n[e].trim();if(!r||r.startsWith("#")){e++;continue}let s=r.match(/^(?:function\s+)?(\w+)\s*\(\s*\)\s*\{(.+)\}\s*$/),i=s??(r.match(/^(?:function\s+)?(\w+)\s*\(\s*\)\s*\{?\s*$/)||r.match(/^function\s+(\w+)\s*\{?\s*$/));if(i){let a=i[1],c=[];if(s){c.push(...s[2].split(";").map(l=>l.trim()).filter(Boolean)),t.push({type:"func",name:a,body:c}),e++;continue}for(e++;e<n.length&&n[e]?.trim()!=="}"&&e<n.length+1;){let l=n[e].trim().replace(/^do\s+/,"");l&&l!=="{"&&c.push(l),e++}e++,t.push({type:"func",name:a,body:c});continue}let o=r.match(/^\(\(\s*(.+?)\s*\)\)$/);if(o){t.push({type:"arith",expr:o[1]}),e++;continue}if(r.startsWith("if ")||r==="if"){let a=r.replace(/^if\s+/,"").replace(/;\s*then\s*$/,"").trim(),c=[],l=[],f=[],u="then",h="";for(e++;e<n.length&&n[e]?.trim()!=="fi";){let p=n[e].trim();p.startsWith("elif ")?(u="elif",h=p.replace(/^elif\s+/,"").replace(/;\s*then\s*$/,"").trim(),l.push({cond:h,body:[]})):p==="else"?u="else":p!=="then"&&(u==="then"?c.push(p):u==="elif"&&l.length>0?l[l.length-1].body.push(p):f.push(p)),e++}t.push({type:"if",cond:a,then_:c,elif:l,else_:f})}else if(r.startsWith("for ")){let a=r.match(/^for\s+(\w+)\s+in\s+(.+?)(?:\s*;\s*do)?$/);if(a){let c=[];for(e++;e<n.length&&n[e]?.trim()!=="done";){let l=n[e].trim().replace(/^do\s+/,"");l&&l!=="do"&&c.push(l),e++}t.push({type:"for",var:a[1],list:a[2],body:c})}else t.push({type:"cmd",line:r})}else if(r.startsWith("while ")){let a=r.replace(/^while\s+/,"").replace(/;\s*do\s*$/,"").trim(),c=[];for(e++;e<n.length&&n[e]?.trim()!=="done";){let l=n[e].trim().replace(/^do\s+/,"");l&&l!=="do"&&c.push(l),e++}t.push({type:"while",cond:a,body:c})}else t.push({type:"cmd",line:r});e++}return t}async function Ro(n,t){let e=await Po(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[,l,f]=o,u=de(t.cwd,f);if(l==="f")return t.shell.vfs.exists(u)&&t.shell.vfs.stat(u).type==="file";if(l==="d")return t.shell.vfs.exists(u)&&t.shell.vfs.stat(u).type==="directory";if(l==="e")return t.shell.vfs.exists(u);if(l==="z")return(f??"").length===0;if(l==="n")return(f??"").length>0}let a=i.match(/^"?([^"]*)"?\s*(==|!=|=|<|>)\s*"?([^"]*)"?$/);if(a){let[,l,f,u]=a;if(f==="=="||f==="=")return l===u;if(f==="!=")return l!==u}let c=i.match(/^(\S+)\s+(-eq|-ne|-lt|-le|-gt|-ge)\s+(\S+)$/);if(c){let[,l,f,u]=c,h=Number(l),p=Number(u);if(f==="-eq")return h===p;if(f==="-ne")return h!==p;if(f==="-lt")return h<p;if(f==="-le")return h<=p;if(f==="-gt")return h>p;if(f==="-ge")return h>=p}}return((await xt(e,t.authUser,t.hostname,t.mode,t.cwd,t.shell,void 0,t.env)).exitCode??0)===0}async function Gn(n,t){let e={exitCode:0},r="";for(let s of n)if(s.type==="cmd"){let i=await Po(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(f=>o.test(f))){for(let f of a){let u=f.match(o);t.env.vars[u[1]]=u[2]}t.env.lastExitCode=0;continue}let c=await(async()=>{let l=i.trim().split(/\s+/)[0]??"",f=t.env.vars[`__func_${l}`];if(f){let u=i.trim().split(/\s+/).slice(1),h={...t.env.vars};u.forEach((y,b)=>{t.env.vars[String(b+1)]=y}),t.env.vars[0]=l;let p=f.split(`
1007
- `),A=await Gn(Yn(p),t);for(let y=1;y<=u.length;y++)delete t.env.vars[String(y)];return Object.assign(t.env.vars,{...h,...t.env.vars}),A}return xt(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}
1008
- `),c.stderr)return{...c,stdout:r.trim()};e=c}else if(s.type==="if"){let i=!1;if(await Ro(s.cond,t)){let o=await Gn(Yn(s.then_),t);o.stdout&&(r+=`${o.stdout}
1009
- `),i=!0}else{for(let o of s.elif)if(await Ro(o.cond,t)){let a=await Gn(Yn(o.body),t);a.stdout&&(r+=`${a.stdout}
1010
- `),i=!0;break}if(!i&&s.else_.length>0){let o=await Gn(Yn(s.else_),t);o.stdout&&(r+=`${o.stdout}
1011
- `)}}}else if(s.type==="func")t.env.vars[`__func_${s.name}`]=s.body.join(`
1012
- `);else if(s.type==="arith"){let i=s.expr.trim(),o=i.match(/^(\w+)\s*(\+\+|--)$/);if(o){let a=parseInt(t.env.vars[o[1]]??"0",10);t.env.vars[o[1]]=String(o[2]==="++"?a+1:a-1)}else{let a=i.match(/^(\w+)\s*([+\-*/])=\s*(.+)$/);if(a){let c=parseInt(t.env.vars[a[1]]??"0",10),l=parseInt(a[3],10),f={"+":c+l,"-":c-l,"*":c*l,"/":Math.floor(c/l)};t.env.vars[a[1]]=String(f[a[2]]??c)}else{let c=wo(i,t.env.vars);Number.isNaN(c)||(t.env.lastExitCode=c===0?1:0)}}}else if(s.type==="for"){let o=(await Po(s.list,t.env.vars,t.env.lastExitCode,t)).trim().split(/\s+/).flatMap(ls);for(let a of o){t.env.vars[s.var]=a;let c=await Gn(Yn(s.body),t);if(c.stdout&&(r+=`${c.stdout}
1013
- `),c.closeSession)return c}}else if(s.type==="while"){let i=0;for(;i<1e3&&await Ro(s.cond,t);){let o=await Gn(Yn(s.body),t);if(o.stdout&&(r+=`${o.stdout}
1014
- `),o.closeSession)return o;i++}}return{...e,stdout:r.trim()||e.stdout}}function Nf(n){let t=[],e="",r=0,s=!1,i=!1,o=0;for(;o<n.length;){let c=n[o];if(!s&&!i){if(c==="'"){s=!0,e+=c,o++;continue}if(c==='"'){i=!0,e+=c,o++;continue}if(c==="{"){r++,e+=c,o++;continue}if(c==="}"){if(r--,e+=c,o++,r===0){let l=e.trim();for(l&&t.push(l),e="";o<n.length&&(n[o]===";"||n[o]===" ");)o++}continue}if(r===0&&(c===";"||c===`
1015
- `)){let l=e.trim();l&&!l.startsWith("#")&&t.push(l),e="",o++;continue}}else s&&c==="'"?s=!1:i&&c==='"'&&(i=!1);e+=c,o++}let a=e.trim();return a&&!a.startsWith("#")&&t.push(a),t}var Bf={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(se(t,"-c")){let i=t[t.indexOf("-c")+1]??"";if(!i)return{stderr:"sh: -c requires a script",exitCode:1};let o=Nf(i),a=Yn(o);return Gn(a,n)}let s=t[0];if(s){let i=de(r,s);if(!e.vfs.exists(i))return{stderr:`sh: ${s}: No such file or directory`,exitCode:1};let o=e.vfs.readFile(i),a=Nf(o),c=Yn(a);return Gn(c,n)}return{stderr:"sh: invalid usage. Use: sh -c 'cmd' or sh <file>",exitCode:1}}};var Rf={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}}},Pf={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}}},Tf={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 Of={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 Lf={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=se(r,["-r"]),o=se(r,["-n"]),a=se(r,["-u"]),c=r.filter(A=>!A.startsWith("-")),u=[...(c.length>0?c.map(A=>{try{return $e(n,de(e,A),"sort"),t.vfs.readFile(de(e,A))}catch{return""}}).join(`
1016
- `):s??"").split(`
1017
- `).filter(Boolean)].sort((A,y)=>o?Number(A)-Number(y):A.localeCompare(y)),h=i?u.reverse():u;return{stdout:(a?[...new Set(h)]:h).join(`
1018
- `),exitCode:0}}};var Df={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=de(r,o);if(!s.vfs.exists(a))return{stderr:`source: ${o}: No such file or directory`,exitCode:1};let c=s.vfs.readFile(a),l=0;for(let f of c.split(`
1019
- `)){let u=f.trim();if(!u||u.startsWith("#"))continue;let h=await xt(u,t,e,"shell",r,s,void 0,i);if(l=h.exitCode??0,h.closeSession||h.switchUser)return h}return{exitCode:l}}};var Mf={name:"su",description:"Switch user",category:"users",params:["[-] [-c <cmd>] [username]"],run:async({authUser:n,shell:t,args:e,hostname:r,mode:s,cwd:i})=>{let o=e.includes("-")||e.includes("-l")||e.includes("--login"),a=e.indexOf("-c"),c=a!==-1?e[a+1]:void 0,f=e.filter((u,h)=>h!==a&&h!==a+1).filter(u=>u!=="-"&&u!=="-l"&&u!=="--login").find(u=>!u.startsWith("-"))??"root";return t.users.listUsers().includes(f)?n==="root"?c?xt(c,f,r,s,o?`/home/${f}`:i,t):{switchUser:f,nextCwd:o?`/home/${f}`:void 0,exitCode:0}:t.users.isSudoer(n)?{sudoChallenge:{username:f,targetUser:f,commandLine:c??null,loginShell:o,prompt:"Password: "},exitCode:0}:{stderr:`su: permission denied
1020
- `,exitCode:1}:{stderr:`su: user '${f}' does not exist
1021
- `,exitCode:1}}};function Tm(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 Uf={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}=Tm(i);if(n!=="root"&&!s.users.isSudoer(n))return{stderr:"sudo: permission denied",exitCode:1};let l=o||"root",f=`[sudo] password for ${n}: `;return n==="root"?!c&&a?{switchUser:l,nextCwd:`/home/${l}`,exitCode:0}:c?xt(c,l,t,e,a?`/home/${l}`:r,s):{stderr:"sudo: missing command",exitCode:1}:{sudoChallenge:{username:n,targetUser:l,commandLine:c,loginShell:a,prompt:f},exitCode:0}}};var $f={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=Jt(r,["-n"]),o=r.find(u=>/^-\d+$/.test(u)),a=typeof i=="string"?parseInt(i,10):o?parseInt(o.slice(1),10):10,c=r.filter(u=>!u.startsWith("-")&&u!==i&&u!==String(a)),l=u=>{let h=u.split(`
1022
- `),p=u.endsWith(`
1023
- `),A=p?h.slice(0,-1):h;return A.slice(Math.max(0,A.length-a)).join(`
1024
- `)+(p?`
1025
- `:"")};if(c.length===0)return{stdout:l(s??""),exitCode:0};let f=[];for(let u of c){let h=de(e,u);try{$e(n,h,"tail"),f.push(l(t.vfs.readFile(h)))}catch{return{stderr:`tail: ${u}: No such file or directory`,exitCode:1}}}return{stdout:f.join(`
1026
- `),exitCode:0}}};var Ff={name:"tar",description:"Archive utility",category:"archive",params:["[-czf|-xzf|-tf] <archive> [files...]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=[],i=!1;for(let h of r)if(/^-[a-zA-Z]{2,}$/.test(h))for(let p of h.slice(1))s.push(`-${p}`);else if(!i&&/^[cxtdru]{1,}[a-zA-Z]*$/.test(h)&&!h.includes("/")&&!h.startsWith("-")){i=!0;for(let p of h)s.push(`-${p}`)}else s.push(h);let o=s.includes("-c"),a=s.includes("-x"),c=s.includes("-t"),l=s.indexOf("-f"),f=l!==-1?s[l+1]:s.find(h=>h.endsWith(".tar")||h.endsWith(".tar.gz")||h.endsWith(".tgz"));if(!o&&!a&&!c)return{stderr:`tar: must specify -c, -x, or -t
1027
- `,exitCode:1};if(!f)return{stderr:`tar: no archive specified
1028
- `,exitCode:1};let u=de(e,f);if(o){let h=new Set;l!==-1&&h.add(l+1);let p=s.filter((y,b)=>!y.startsWith("-")&&y!==f&&!h.has(b)),A={};for(let y of p){let b=de(e,y);try{if(t.vfs.stat(b).type==="file")A[y]=t.vfs.readFile(b);else{let B=(H,C)=>{for(let M of t.vfs.list(H)){let Q=`${H}/${M}`,N=`${C}/${M}`;t.vfs.stat(Q).type==="file"?A[N]=t.vfs.readFile(Q):B(Q,N)}};B(b,y)}}catch{return{stderr:`tar: ${y}: No such file or directory`,exitCode:1}}}return t.writeFileAsUser(n,u,JSON.stringify(A)),{exitCode:0}}if(c||a){let h;try{h=JSON.parse(t.vfs.readFile(u))}catch{return{stderr:`tar: ${f}: cannot open archive`,exitCode:1}}if(c)return{stdout:Object.keys(h).join(`
1029
- `),exitCode:0};for(let[p,A]of Object.entries(h))t.writeFileAsUser(n,de(e,p),A);return{exitCode:0}}return{stderr:"tar: must specify -c, -x, or -t",exitCode:1}}};var Hf={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=se(r,["-a"]),o=r.filter(c=>!c.startsWith("-")),a=s??"";for(let c of o){let l=de(e,c);if(i){let f=(()=>{try{return t.vfs.readFile(l)}catch{return""}})();t.writeFileAsUser(n,l,f+a)}else t.writeFileAsUser(n,l,a)}return{stdout:a,exitCode:0}}};function Dr(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!Dr(n.slice(1),t,e);let r=n.indexOf("-a");if(r!==-1)return Dr(n.slice(0,r),t,e)&&Dr(n.slice(r+1),t,e);let s=n.indexOf("-o");if(s!==-1)return Dr(n.slice(0,s),t,e)||Dr(n.slice(s+1),t,e);if(n.length===2){let[i,o=""]=n,c=(l=>l.startsWith("/")?l:`${e}/${l}`.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),l=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===l;case"-ne":return c!==l;case"-lt":return c<l;case"-le":return c<=l;case"-gt":return c>l;case"-ge":return c>=l}}return n.length===1?(n[0]??"").length>0:!1}var Qf={name:"test",aliases:["["],description:"Evaluate conditional expression",category:"shell",params:["<expression>"],run:({args:n,shell:t,cwd:e})=>{try{return{exitCode:Dr([...n],t,e)?0:1}}catch{return{stderr:"test: malformed expression",exitCode:2}}}};var Wf={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=de(e,s);$e(n,i,"touch"),t.vfs.exists(i)||t.writeFileAsUser(n,i,"")}return{exitCode:0}}};function Om(n){return n.replace(/\\n/g,`
1030
- `).replace(/\\t/g," ").replace(/\\r/g,"\r").replace(/\\\\/g,"\\")}function qf(n){let t=[],e=Om(n),r=0;for(;r<e.length;){if(r+2<e.length&&e[r+1]==="-"){let s=e.charCodeAt(r),i=e.charCodeAt(r+2);if(s<=i){for(let o=s;o<=i;o++)t.push(String.fromCharCode(o));r+=3;continue}}t.push(e[r]),r++}return t}var Kf={name:"tr",description:"Translate or delete characters",category:"text",params:["[-d] [-s] <set1> [set2]"],run:({args:n,stdin:t})=>{let e=se(n,["-d"]),r=se(n,["-s"]),s=n.filter(c=>!c.startsWith("-")),i=qf(s[0]??""),o=qf(s[1]??""),a=t??"";if(e){let c=new Set(i);a=[...a].filter(l=>!c.has(l)).join("")}else if(o.length>0){let c=new Map;for(let l=0;l<i.length;l++)c.set(i[l],o[l]??o[o.length-1]??"");a=[...a].map(l=>c.get(l)??l).join("")}if(r&&o.length>0){let c=new Set(o);a=a.replace(/(.)\1+/g,(l,f)=>c.has(f)?f:l)}return{stdout:a,exitCode:0}}};var Vf={name:"tree",description:"Display directory tree",category:"navigation",params:["[path]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=de(e,Mn(r,0)??e);return $e(n,s,"tree"),{stdout:t.vfs.tree(s),exitCode:0}}};var zf={name:"true",description:"Return success exit code",category:"shell",params:[],run:()=>({exitCode:0})},Yf={name:"false",description:"Return failure exit code",category:"shell",params:[],run:()=>({exitCode:1})};var Gf={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(Sn(o)){s.push(`${o} is a shell builtin`);continue}let a=!1;for(let c of r){let l=`${c}/${o}`;if(t.vfs.exists(l)){s.push(`${o} is ${l}`),a=!0;break}}a||(s.push(`${o}: not found`),i=1)}return{stdout:s.join(`
1031
- `),exitCode:i}}};var jf={name:"uname",description:"Print system information",category:"system",params:["[-a] [-s] [-r] [-m]"],run:({shell:n,args:t})=>{let e=se(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}:se(t,["-r"])?{stdout:s,exitCode:0}:se(t,["-m"])?{stdout:i,exitCode:0}:{stdout:r,exitCode:0}}};var Xf={name:"uniq",description:"Report or filter out repeated lines",category:"text",params:["[-c] [-d] [-u] [file]"],run:({args:n,stdin:t})=>{let e=se(n,["-c"]),r=se(n,["-d"]),s=se(n,["-u"]),i=(t??"").split(`
1032
- `),o=[],a=0;for(;a<i.length;){let c=a;for(;c<i.length&&i[c]===i[a];)c++;let l=c-a,f=i[a];if(r&&l===1){a=c;continue}if(s&&l>1){a=c;continue}o.push(e?`${String(l).padStart(4)} ${f}`:f),a=c}return{stdout:o.join(`
1033
- `),exitCode:0}}};var Jf={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 Zf={name:"uptime",description:"Tell how long the system has been running",category:"system",params:["[-p] [-s]"],run:({args:n,shell:t})=>{let e=se(n,["-p"]),r=se(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),l=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")}`,f=t.users.listActiveSessions().length,u=(Math.random()*.5).toFixed(2);return{stdout:` ${c} up ${l}, ${f} user${f!==1?"s":""}, load average: ${u}, ${u}, ${u}`,exitCode:0}}};var eu={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=se(r,["-l"]),o=se(r,["-w"]),a=se(r,["-c"]),c=!i&&!o&&!a,l=r.filter(h=>!h.startsWith("-")),f=(h,p)=>{let A=h.length===0?0:h.trim().split(`
1034
- `).length,y=h.trim().split(/\s+/).filter(Boolean).length,b=Buffer.byteLength(h,"utf8"),x=[];return(c||i)&&x.push(String(A).padStart(7)),(c||o)&&x.push(String(y).padStart(7)),(c||a)&&x.push(String(b).padStart(7)),p&&x.push(` ${p}`),x.join("")};if(l.length===0)return{stdout:f(s??"",""),exitCode:0};let u=[];for(let h of l){let p=de(e,h);try{$e(n,p,"wc");let A=t.vfs.readFile(p);u.push(f(A,h))}catch{return{stderr:`wc: ${h}: No such file or directory`,exitCode:1}}}return{stdout:u.join(`
1035
- `),exitCode:0}}};var tu={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(se(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(`
1036
- `),exitCode:0};if(se(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
1037
- Usage: wget [OPTION]... [URL]...`,exitCode:1};let a=o.startsWith("http://")||o.startsWith("https://")?o:`http://${o}`;if(!a)return{stderr:`wget: missing URL
1038
- Usage: wget [OPTION]... [URL]...`,exitCode:1};let c=s.get("-O")??s.get("--output-document")??null,l=s.get("-P")??s.get("--directory-prefix")??null,f=se(e,["-q","--quiet"]),u=c==="-"?null:c??Zc(a),h=u?de(t,l?`${l}/${u}`:u):null;h&&$e(n,h,"wget");let p=[];f||(p.push(`--${new Date().toISOString()}-- ${a}`),p.push(`Resolving ${new URL(a).host}...`),p.push(`Connecting to ${new URL(a).host}...`));let A;try{A=await fetch(a,{headers:{"User-Agent":"Wget/1.21.3 (Fortune GNU/Linux)"}})}catch(b){let x=b instanceof Error?b.message:String(b);return p.push(`wget: unable to resolve host: ${x}`),{stderr:p.join(`
1039
- `),exitCode:4}}if(!A.ok)return p.push(`ERROR ${A.status}: ${A.statusText}`),{stderr:p.join(`
1040
- `),exitCode:8};let y;try{y=await A.text()}catch{return{stderr:"wget: failed to read response",exitCode:1}}if(!f){let b=A.headers.get("content-type")??"application/octet-stream";p.push(`HTTP request sent, awaiting response... ${A.status} ${A.statusText}`),p.push(`Length: ${y.length} [${b}]`)}return c==="-"?{stdout:y,stderr:p.join(`
1041
- `)||void 0,exitCode:0}:h?(r.writeFileAsUser(n,h,y),f||p.push(`Saving to: '${h}'
1042
- ${h} 100%[==================>] ${y.length} B`),{stderr:p.join(`
1043
- `)||void 0,exitCode:0}):{stdout:y,exitCode:0}}};var nu={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 l=`${c}/${o}`;if(t.vfs.exists(l)&&t.vfs.stat(l).type==="file"){s.push(l),a=!0;break}}a||(i=!0)}return s.length===0?{exitCode:1}:{stdout:s.join(`
1044
- `),exitCode:i?1:0}}};function ys(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 ru={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:ys(r);return`${e.username} ${e.tty} ${s} (${e.remoteAddress||"unknown"})`}).join(`
1045
- `),exitCode:0})};var iu={name:"whoami",description:"Print current user",category:"system",params:[],run:({authUser:n})=>({stdout:n,exitCode:0})};var su={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",l=s.slice(1),f=(i??"").trim().split(/\s+/).filter(Boolean);if(f.length===0)return{exitCode:0};let u=[c,...l,...f].join(" ");return xt(u,n,t,e,r,o,void 0,a)}};var Lm=[Ef,ol,Vl,Vf,sl,Wf,xf,jl,ll,Xl,Hl,Ql,al,Wl,ql,wl,Cl,wf,rl,Lf,Xf,eu,Bl,$f,ul,Kf,Hf,su,gl,Ff,kl,Nl,il,iu,ru,Ml,$l,vl,jf,Af,Fl,ml,yl,dl,Of,mf,_l,Sl,xl,If,Jf,Bf,cl,bl,Zl,Ul,fl,tu,Gc,pf,pl,Uf,Mf,lf,tl,nl,Al,El,nu,Gf,Gl,Xc,Jc,Qf,Df,Dl,gf,bf,hl,Rf,Pf,Tf,zf,Yf,df,hf,uf,Sf,Zf,Il,zl],ou=[],yi=new Map,_s=null,Dm=Ll(()=>Oo().map(n=>n.name));function To(){yi.clear();for(let n of Oo()){yi.set(n.name,n);for(let t of n.aliases??[])yi.set(t,n)}_s=Array.from(yi.keys()).sort()}function Oo(){return[...Lm,...ou,Dm]}function Lo(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");ou.push(t),To()}function Do(n,t,e){return{name:n,params:t,run:e}}function Mo(){return _s||To(),_s}function Io(){return Oo()}function Sn(n){return _s||To(),yi.get(n.toLowerCase())}var dx=mn("SshClient");var gp=require("node:events"),Ap=Wt(vc(),1);var cp=require("node:events");var Sr=Wt(require("node:os"),1);var Hh=require("node:events"),rt=Wt(require("node:fs"),1),nn=Wt(require("node:path"),1),_r=require("node:zlib");var Rc=Buffer.from([86,70,83,33]),BE=1,kc=1,Lh=2,Nc=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 Dh(n,t){if(t.type==="file"){let e=t;n.writeUint8(kc),n.writeString(e.name),n.writeUint32(e.mode),n.writeFloat64(e.createdAt),n.writeFloat64(e.updatedAt),n.writeUint8(e.compressed?1:0),n.writeBytes(e.content)}else if(t.type==="stub"){let e=t;n.writeUint8(kc),n.writeString(e.name),n.writeUint32(e.mode),n.writeFloat64(e.createdAt),n.writeFloat64(e.updatedAt),n.writeUint8(0),n.writeBytes(Buffer.from(e.stubContent,"utf8"))}else{let e=t;n.writeUint8(Lh),n.writeString(e.name),n.writeUint32(e.mode),n.writeFloat64(e.createdAt),n.writeFloat64(e.updatedAt);let r=Object.values(e.children);n.writeUint32(r.length);for(let s of r)Dh(n,s)}}function Pc(n){let t=new Nc;return t.write(Rc),t.writeUint8(BE),Dh(t,n),t.toBuffer()}var Bc=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 Mh(n){let t=n.readUint8(),e=n.readString(),r=n.readUint32(),s=n.readFloat64(),i=n.readFloat64();if(t===kc){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===Lh){let o=n.readUint32(),a=Object.create(null);for(let c=0;c<o;c++){let l=Mh(n);a[l.name]=l}return{type:"directory",name:e,mode:r,createdAt:s,updatedAt:i,children:a,_childCount:o}}throw new Error(`[VFS binary] Unknown node type: 0x${t.toString(16)}`)}function Er(n){if(n.length<5)throw new Error("[VFS binary] Buffer too short");if(!n.slice(0,4).equals(Rc))throw new Error("[VFS binary] Invalid magic \u2014 not a VFS binary snapshot");let e=new Bc(n);for(let s=0;s<5;s++)e.readUint8();let r=Mh(e);if(r.type!=="directory")throw new Error("[VFS binary] Root node must be a directory");return r}function Uh(n){return n.length>=4&&n.slice(0,4).equals(Rc)}var Kt=Wt(require("node:fs"),1),ft={WRITE:1,MKDIR:2,REMOVE:3,CHMOD:4,MOVE:5,SYMLINK:6},Gi="utf8";function RE(n,t,e){let r=Buffer.from(e,Gi);return n.writeUInt16LE(r.length,t),r.copy(n,t+2),2+r.length}function PE(n){let t=Buffer.from(n.path,Gi),e=0;n.op===ft.WRITE?e=4+(n.content?.length??0)+4:n.op===ft.MKDIR?e=4:n.op===ft.REMOVE?e=0:n.op===ft.CHMOD?e=4:(n.op===ft.MOVE||n.op===ft.SYMLINK)&&(e=2+Buffer.byteLength(n.dest??"",Gi));let r=3+t.length+e,s=Buffer.allocUnsafe(r),i=0;if(s.writeUInt8(n.op,i++),s.writeUInt16LE(t.length,i),i+=2,t.copy(s,i),i+=t.length,n.op===ft.WRITE){let o=n.content??Buffer.alloc(0);s.writeUInt32LE(o.length,i),i+=4,o.copy(s,i),i+=o.length,s.writeUInt32LE(n.mode??420,i),i+=4}else n.op===ft.MKDIR?(s.writeUInt32LE(n.mode??493,i),i+=4):n.op===ft.CHMOD?(s.writeUInt32LE(n.mode??420,i),i+=4):(n.op===ft.MOVE||n.op===ft.SYMLINK)&&(i+=RE(s,i,n.dest??""));return s}function TE(n){let t=[],e=0;try{for(;e<n.length&&!(e+3>n.length);){let r=n.readUInt8(e++),s=n.readUInt16LE(e);if(e+=2,e+s>n.length)break;let i=n.subarray(e,e+s).toString(Gi);if(e+=s,r===ft.WRITE){if(e+4>n.length)break;let o=n.readUInt32LE(e);if(e+=4,e+o+4>n.length)break;let a=Buffer.from(n.subarray(e,e+o));e+=o;let c=n.readUInt32LE(e);e+=4,t.push({op:r,path:i,content:a,mode:c})}else if(r===ft.MKDIR){if(e+4>n.length)break;let o=n.readUInt32LE(e);e+=4,t.push({op:r,path:i,mode:o})}else if(r===ft.REMOVE)t.push({op:r,path:i});else if(r===ft.CHMOD){if(e+4>n.length)break;let o=n.readUInt32LE(e);e+=4,t.push({op:r,path:i,mode:o})}else if(r===ft.MOVE||r===ft.SYMLINK){if(e+2>n.length)break;let o=n.readUInt16LE(e);if(e+=2,e+o>n.length)break;let a=n.subarray(e,e+o).toString(Gi);e+=o,t.push({op:r,path:i,dest:a})}else break}}catch{}return t}function $h(n,t){let e=PE(t),r=Kt.openSync(n,Kt.constants.O_WRONLY|Kt.constants.O_CREAT|Kt.constants.O_APPEND);try{Kt.writeSync(r,e)}finally{Kt.closeSync(r)}}function Tc(n){if(!Kt.existsSync(n))return[];let t=Kt.readFileSync(n);return t.length===0?[]:TE(t)}function Fh(n){Kt.existsSync(n)&&Kt.unlinkSync(n)}var go=Wt(require("node:path"),1);function ut(n){if(!n||n.trim()==="")return"/";let t=go.posix.normalize(n.startsWith("/")?n:`/${n}`);return t===""?"/":t}function OE(n){return n.split("/").filter(Boolean)}function Vt(n,t){let e=ut(t);if(e==="/")return n;let r=OE(e),s=n;for(let i of r){if(s.type!=="directory")throw new Error(`Path '${e}' does not exist.`);let o=s.children[i];if(!o)throw new Error(`Path '${e}' does not exist.`);s=o}return s}function yr(n,t,e,r){let s=ut(t);if(s==="/")throw new Error("Root path has no parent directory.");let i=go.posix.dirname(s),o=go.posix.basename(s);if(!o)throw new Error(`Invalid path '${t}'.`);e&&r(i);let a=Vt(n,i);if(a.type!=="directory")throw new Error(`Parent path '${i}' is not a directory.`);return{parent:a,name:o}}var Oc=class n extends Hh.EventEmitter{root;mode;snapshotFile;journalFile;evictionThreshold;flushAfterNWrites;_writesSinceFlush=0;_flushTimer=null;_dirty=!1;mounts=new Map;static isBrowser=typeof process>"u"||typeof process.versions?.node>"u";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=nn.resolve(t.snapshotPath,"vfs-snapshot.vfsb"),this.journalFile=nn.resolve(t.snapshotPath,"vfs-journal.bin"),this.evictionThreshold=t.evictionThresholdBytes??64*1024,this.flushAfterNWrites=t.flushAfterNWrites??500;let e=t.flushIntervalMs??3e4;e>0&&(this._flushTimer=setInterval(()=>{this._dirty&&this._autoFlush()},e),typeof this._flushTimer=="object"&&this._flushTimer!==null&&"unref"in this._flushTimer&&this._flushTimer.unref())}else this.snapshotFile=null,this.journalFile=null,this.evictionThreshold=0,this.flushAfterNWrites=0;this.root=this.makeDir("",493)}makeDir(t,e){let r=Date.now();return{type:"directory",name:t,mode:e,createdAt:r,updatedAt:r,children:Object.create(null),_childCount:0}}makeFile(t,e,r,s){let i=Date.now();return{type:"file",name:t,content:e,mode:r,compressed:s,createdAt:i,updatedAt:i}}makeStub(t,e,r){let s=Date.now();return{type:"stub",name:t,stubContent:e,mode:r,createdAt:s,updatedAt:s}}writeStub(t,e,r=420){let s=ut(t),{parent:i,name:o}=yr(this.root,s,!0,c=>this.mkdirRecursive(c,493)),a=i.children[o];if(a?.type==="directory")throw new Error(`Cannot write stub '${s}': path is a directory.`);a?.type!=="file"&&(a||i._childCount++,i.children[o]=this.makeStub(o,e,r))}mkdirRecursive(t,e){let r=ut(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[a];if(!c)c=this.makeDir(a,e),i.children[a]=c,i._childCount++,this.emit("dir:create",{path:o,mode:e}),this._journal({op:ft.MKDIR,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)){if(!rt.existsSync(this.snapshotFile)){if(this.journalFile){let t=Tc(this.journalFile);t.length>0&&this._replayJournal(t)}return}try{let t=rt.readFileSync(this.snapshotFile);if(Uh(t))this.root=Er(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.")}if(this.emit("snapshot:restore",{path:this.snapshotFile}),this.journalFile){let e=Tc(this.journalFile);e.length>0&&this._replayJournal(e)}}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=nn.dirname(this.snapshotFile);rt.mkdirSync(t,{recursive:!0});let e=Pc(this.root);rt.writeFileSync(this.snapshotFile,e),this.journalFile&&Fh(this.journalFile),this._dirty=!1,this._writesSinceFlush=0,this.emit("mirror:flush",{path:this.snapshotFile}),this.evictLargeFiles()}getMode(){return this.mode}getSnapshotPath(){return this.snapshotFile}async _autoFlush(){this._dirty&&await this.flushMirror()}_markDirty(){this._dirty=!0,this.flushAfterNWrites>0&&(this._writesSinceFlush++,this._writesSinceFlush>=this.flushAfterNWrites&&(this._writesSinceFlush=0,this._autoFlush()))}async stopAutoFlush(){this._flushTimer!==null&&(clearInterval(this._flushTimer),this._flushTimer=null),this._dirty&&await this.flushMirror()}importRootTree(t){let e=this._replayMode;this._replayMode=!0;try{this.root=t}finally{this._replayMode=e}}encodeBinary(){return Pc(this.root)}releaseTree(){this.root=this.makeDir("",493)}_replayMode=!1;_journal(t){this.journalFile&&!this._replayMode&&($h(this.journalFile,t),this._markDirty())}_replayJournal(t){this._replayMode=!0;try{for(let e of t)try{e.op===ft.WRITE?this.writeFile(e.path,e.content??Buffer.alloc(0),{mode:e.mode}):e.op===ft.MKDIR?this.mkdir(e.path,e.mode):e.op===ft.REMOVE?this.exists(e.path)&&this.remove(e.path,{recursive:!0}):e.op===ft.CHMOD?this.exists(e.path)&&this.chmod(e.path,e.mode??420):e.op===ft.MOVE?this.exists(e.path)&&e.dest&&this.move(e.path,e.dest):e.op===ft.SYMLINK&&e.dest&&this.symlink(e.dest,e.path)}catch{}}finally{this._replayMode=!1}}evictLargeFiles(){!this.snapshotFile||this.evictionThreshold===0||rt.existsSync(this.snapshotFile)&&this._evictDir(this.root)}_evictDir(t){for(let e of Object.values(t.children))if(e.type==="directory")this._evictDir(e);else if(e.type==="file"&&!e.evicted){let r=e.compressed?e.size??e.content.length*2:e.content.length;r>this.evictionThreshold&&(e.size=r,e.content=Buffer.alloc(0),e.evicted=!0)}}_reloadEvicted(t,e){if(!(!t.evicted||!this.snapshotFile)&&rt.existsSync(this.snapshotFile))try{let r=rt.readFileSync(this.snapshotFile),s=Er(r),i=e.split("/").filter(Boolean),o=s;for(let a of i){if(o.type!=="directory")return;let c=o.children[a];if(!c)return;o=c}o.type==="file"&&(t.content=o.content,t.compressed=o.compressed,t.evicted=void 0)}catch{}}mount(t,e,{readOnly:r=!0}={}){if(n.isBrowser)return;let s=ut(t),i=nn.resolve(e);if(!rt.existsSync(i))throw new Error(`VirtualFileSystem.mount: host path does not exist: "${i}"`);if(!rt.statSync(i).isDirectory())throw new Error(`VirtualFileSystem.mount: host path is not a directory: "${i}"`);this.mkdir(s),this.mounts.set(s,{hostPath:i,readOnly:r}),this.emit("mount",{vPath:s,hostPath:i,readOnly:r})}unmount(t){let e=ut(t);this.mounts.delete(e)&&this.emit("unmount",{vPath:e})}getMounts(){return[...this.mounts.entries()].map(([t,e])=>({vPath:t,...e}))}resolveMount(t){let e=ut(t),r=[...this.mounts.entries()].sort(([s],[i])=>i.length-s.length);for(let[s,i]of r)if(e===s||e.startsWith(`${s}/`)){let o=e.slice(s.length).replace(/^\//,""),a=o?nn.join(i.hostPath,o):i.hostPath;return{hostPath:i.hostPath,readOnly:i.readOnly,relPath:o,fullHostPath:a}}return null}mkdir(t,e=493){let r=ut(t),s=(()=>{try{return Vt(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=this.resolveMount(t);if(s){if(s.readOnly)throw new Error(`EROFS: read-only file system, open '${s.fullHostPath}'`);let p=nn.dirname(s.fullHostPath);rt.existsSync(p)||rt.mkdirSync(p,{recursive:!0}),rt.writeFileSync(s.fullHostPath,Buffer.isBuffer(e)?e:Buffer.from(e,"utf8"));return}let i=ut(t),{parent:o,name:a}=yr(this.root,i,!0,p=>this.mkdirRecursive(p,493)),c=o.children[a];if(c?.type==="directory")throw new Error(`Cannot write file '${i}': path is a directory.`);let l=Buffer.isBuffer(e)?e:Buffer.from(e,"utf8"),f=r.compress??!1,u=f?(0,_r.gzipSync)(l):l,h=r.mode??420;if(c&&c.type==="file"){let p=c;p.content=u,p.compressed=f,p.mode=h,p.updatedAt=Date.now()}else c||o._childCount++,o.children[a]=this.makeFile(a,u,h,f);this.emit("file:write",{path:i,size:u.length}),this._journal({op:ft.WRITE,path:i,content:l,mode:h})}readFile(t){let e=this.resolveMount(t);if(e){if(!rt.existsSync(e.fullHostPath))throw new Error(`ENOENT: no such file or directory, open '${e.fullHostPath}'`);return rt.readFileSync(e.fullHostPath,"utf8")}let r=ut(t),s=Vt(this.root,r);if(s.type==="stub")return this.emit("file:read",{path:r,size:s.stubContent.length}),s.stubContent;if(s.type!=="file")throw new Error(`Cannot read '${t}': not a file.`);let i=s;i.evicted&&this._reloadEvicted(i,r);let o=i.compressed?(0,_r.gunzipSync)(i.content):i.content;return this.emit("file:read",{path:r,size:o.length}),o.toString("utf8")}readFileRaw(t){let e=this.resolveMount(t);if(e){if(!rt.existsSync(e.fullHostPath))throw new Error(`ENOENT: no such file or directory, open '${e.fullHostPath}'`);return rt.readFileSync(e.fullHostPath)}let r=ut(t),s=Vt(this.root,r);if(s.type==="stub"){let a=Buffer.from(s.stubContent,"utf8");return this.emit("file:read",{path:r,size:a.length}),a}if(s.type!=="file")throw new Error(`Cannot read '${t}': not a file.`);let i=s;i.evicted&&this._reloadEvicted(i,r);let o=i.compressed?(0,_r.gunzipSync)(i.content):i.content;return this.emit("file:read",{path:r,size:o.length}),o}exists(t){let e=this.resolveMount(t);if(e)return rt.existsSync(e.fullHostPath);try{return Vt(this.root,ut(t)),!0}catch{return!1}}chmod(t,e){let r=ut(t);Vt(this.root,r).mode=e,this._journal({op:ft.CHMOD,path:r,mode:e})}stat(t){let e=this.resolveMount(t);if(e){if(!rt.existsSync(e.fullHostPath))throw new Error(`ENOENT: stat '${e.fullHostPath}'`);let a=rt.statSync(e.fullHostPath),c=e.relPath.split("/").pop()??e.fullHostPath.split("/").pop()??"",l=a.mtime;return a.isDirectory()?{type:"directory",name:c,path:ut(t),mode:493,createdAt:a.birthtime,updatedAt:l,childrenCount:rt.readdirSync(e.fullHostPath).length}:{type:"file",name:c,path:ut(t),mode:e.readOnly?292:420,createdAt:a.birthtime,updatedAt:l,compressed:!1,size:a.size}}let r=ut(t),s=Vt(this.root,r),i=r==="/"?"":nn.posix.basename(r);if(s.type==="stub"){let a=s;return{type:"file",name:i,path:r,mode:a.mode,createdAt:new Date(a.createdAt),updatedAt:new Date(a.updatedAt),compressed:!1,size:a.stubContent.length}}if(s.type==="file"){let a=s;return{type:"file",name:i,path:r,mode:a.mode,createdAt:new Date(a.createdAt),updatedAt:new Date(a.updatedAt),compressed:a.compressed,size:a.evicted?a.size??0:a.content.length}}let o=s;return{type:"directory",name:i,path:r,mode:o.mode,createdAt:new Date(o.createdAt),updatedAt:new Date(o.updatedAt),childrenCount:o._childCount}}list(t="/"){let e=this.resolveMount(t);if(e){if(!rt.existsSync(e.fullHostPath))return[];try{return rt.readdirSync(e.fullHostPath).sort()}catch{return[]}}let r=ut(t),s=Vt(this.root,r);if(s.type!=="directory")throw new Error(`Cannot list '${t}': not a directory.`);return Object.keys(s.children).sort()}tree(t="/"){let e=ut(t),r=Vt(this.root,e);if(r.type!=="directory")throw new Error(`Cannot render tree for '${t}': not a directory.`);let s=t==="/"?"/":nn.posix.basename(e);return this.renderTreeLines(r,s)}renderTreeLines(t,e){let r=[e],s=Object.keys(t.children).sort();for(let i=0;i<s.length;i++){let o=s[i],a=t.children[o],c=i===s.length-1,l=c?"\u2514\u2500\u2500 ":"\u251C\u2500\u2500 ",f=c?" ":"\u2502 ";if(r.push(`${l}${o}`),a.type==="directory"){let u=this.renderTreeLines(a,"").split(`
1046
- `).slice(1).map(h=>`${f}${h}`);r.push(...u)}}return r.join(`
1047
- `)}getUsageBytes(t="/"){return this.computeUsage(Vt(this.root,ut(t)))}computeUsage(t){if(t.type==="file")return t.content.length;if(t.type==="stub")return t.stubContent.length;let e=0;for(let r of Object.values(t.children))e+=this.computeUsage(r);return e}compressFile(t){let e=Vt(this.root,ut(t));if(e.type!=="file")throw new Error(`Cannot compress '${t}': not a file.`);let r=e;r.compressed||(r.content=(0,_r.gzipSync)(r.content),r.compressed=!0,r.updatedAt=Date.now())}decompressFile(t){let e=Vt(this.root,ut(t));if(e.type!=="file")throw new Error(`Cannot decompress '${t}': not a file.`);let r=e;r.compressed&&(r.content=(0,_r.gunzipSync)(r.content),r.compressed=!1,r.updatedAt=Date.now())}symlink(t,e){let r=ut(e),s=t.startsWith("/")?ut(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:Date.now(),updatedAt:Date.now()};i.children[o]=a,i._childCount++,this._journal({op:ft.SYMLINK,path:r,dest:s}),this.emit("symlink:create",{link:r,target:s})}isSymlink(t){try{let e=Vt(this.root,ut(t));return e.type==="file"&&e.mode===41471}catch{return!1}}resolveSymlink(t,e=8){let r=ut(t);for(let s=0;s<e;s++){try{let i=Vt(this.root,r);if(i.type==="file"&&i.mode===41471){let o=i.content.toString("utf8");r=o.startsWith("/")?o:ut(nn.posix.join(nn.posix.dirname(r),o));continue}}catch{break}return r}throw new Error(`Too many levels of symbolic links: ${t}`)}remove(t,e={}){let r=this.resolveMount(t);if(r){if(r.readOnly)throw new Error(`EROFS: read-only file system, unlink '${r.fullHostPath}'`);if(!rt.existsSync(r.fullHostPath))throw new Error(`ENOENT: no such file or directory, unlink '${r.fullHostPath}'`);rt.statSync(r.fullHostPath).isDirectory()?rt.rmSync(r.fullHostPath,{recursive:e.recursive??!1}):rt.unlinkSync(r.fullHostPath);return}let s=ut(t);if(s==="/")throw new Error("Cannot remove root directory.");let i=Vt(this.root,s);if(i.type==="directory"){let c=i;if(!e.recursive&&c._childCount>0)throw new Error(`Directory '${s}' is not empty. Use recursive option.`)}let{parent:o,name:a}=yr(this.root,s,!1,()=>{});delete o.children[a],o._childCount--,this.emit("node:remove",{path:s}),this._journal({op:ft.REMOVE,path:s})}move(t,e){let r=ut(t),s=ut(e);if(r==="/"||s==="/")throw new Error("Cannot move root directory.");let i=Vt(this.root,r);if(this.exists(s))throw new Error(`Destination '${s}' already exists.`);this.mkdirRecursive(nn.posix.dirname(s),493);let{parent:o,name:a}=yr(this.root,s,!1,()=>{}),{parent:c,name:l}=yr(this.root,r,!1,()=>{});delete c.children[l],c._childCount--,i.name=a,o.children[a]=i,o._childCount++,this._journal({op:ft.MOVE,path:r,dest:s})}toSnapshot(){return{root:this.serializeDir(this.root)}}serializeDir(t){let e=[];for(let r of Object.values(t.children))r.type==="stub"?e.push({type:"file",name:r.name,mode:r.mode,createdAt:new Date(r.createdAt).toISOString(),updatedAt:new Date(r.updatedAt).toISOString(),compressed:!1,contentBase64:Buffer.from(r.stubContent,"utf8").toString("base64")}):r.type==="file"?e.push(this.serializeFile(r)):e.push(this.serializeDir(r));return{type:"directory",name:t.name,mode:t.mode,createdAt:new Date(t.createdAt).toISOString(),updatedAt:new Date(t.updatedAt).toISOString(),children:e}}serializeFile(t){return{type:"file",name:t.name,mode:t.mode,createdAt:new Date(t.createdAt).toISOString(),updatedAt:new Date(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:Date.parse(t.createdAt),updatedAt:Date.parse(t.updatedAt),children:Object.create(null),_childCount:0};for(let s of t.children){if(s.type==="file"){let i=s;r.children[i.name]={type:"file",name:i.name,mode:i.mode,createdAt:Date.parse(i.createdAt),updatedAt:Date.parse(i.updatedAt),compressed:i.compressed,content:Buffer.from(i.contentBase64,"base64")}}else{let i=this.deserializeDir(s,s.name);r.children[s.name]=i}r._childCount++}return r}},ji=Oc;function ce(n,t,e=493){n.exists(t)||n.mkdir(t,e)}function fe(n,t,e,r=420){n.writeStub(t,e,r)}function bt(n,t,e){n.writeFile(t,e)}function LE(n){let t=2166136261;for(let e=0;e<n.length;e++)t^=n.charCodeAt(e),t=Math.imul(t,16777619);return t>>>0}function DE(n,t,e){ce(n,"/etc"),fe(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(`
1048
- `)}
1049
- `),fe(n,"/etc/debian_version",`12.0
1050
- `),fe(n,"/etc/hostname",`${t}
1051
- `),fe(n,"/etc/shells",`/bin/sh
1052
- /bin/bash
1053
- /usr/bin/bash
1054
- `),fe(n,"/etc/profile",`${["export PATH=/usr/local/bin:/usr/bin:/bin","export PS1='\\u@\\h:\\w\\$ '"].join(`
1055
- `)}
1056
- `),fe(n,"/etc/issue",`Fortune GNU/Linux 1.0 \\n \\l
1057
- `),fe(n,"/etc/motd",["",`Welcome to ${e.os}`,`Kernel: ${e.kernel}`,""].join(`
1058
- `)),ce(n,"/etc/apt"),ce(n,"/etc/apt/sources.list.d"),fe(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(`
1059
- `)}
1060
- `),ce(n,"/etc/network"),fe(n,"/etc/network/interfaces",`${["auto lo","iface lo inet loopback","","auto eth0","iface eth0 inet dhcp"].join(`
1061
- `)}
1062
- `),fe(n,"/etc/resolv.conf",`nameserver 1.1.1.1
1063
- nameserver 8.8.8.8
1064
- `),fe(n,"/etc/hosts",`${["127.0.0.1 localhost",`127.0.1.1 ${t}`,"::1 localhost ip6-localhost ip6-loopback"].join(`
1065
- `)}
1066
- `),ce(n,"/etc/cron.d"),ce(n,"/etc/init.d"),ce(n,"/etc/systemd"),ce(n,"/etc/systemd/system"),fe(n,"/etc/fstab",`${["# <file system> <mount point> <type> <options> <dump> <pass>","UUID=00000000-0000-0000-0000-000000000001 / ext4 errors=remount-ro 0 1","UUID=00000000-0000-0000-0000-000000000002 /boot ext4 defaults 0 2","UUID=00000000-0000-0000-0000-000000000003 none swap sw 0 0","tmpfs /tmp tmpfs defaults,noatime 0 0","tmpfs /run tmpfs defaults,noatime 0 0"].join(`
1067
- `)}
1068
- `),fe(n,"/etc/login.defs",`${["MAIL_DIR /var/mail","PASS_MAX_DAYS 99999","PASS_MIN_DAYS 0","PASS_WARN_AGE 7","UID_MIN 1000","UID_MAX 60000","GID_MIN 1000","GID_MAX 60000","CREATE_HOME yes","UMASK 022","USERGROUPS_ENAB yes","ENCRYPT_METHOD SHA512"].join(`
1069
- `)}
1070
- `),ce(n,"/etc/security"),fe(n,"/etc/security/limits.conf",`# /etc/security/limits.conf
1071
- `),fe(n,"/etc/security/access.conf",`# /etc/security/access.conf
1072
- `),ce(n,"/etc/pam.d"),fe(n,"/etc/pam.d/common-auth",`auth required pam_unix.so
1073
- `),fe(n,"/etc/pam.d/common-account",`account required pam_unix.so
1074
- `),fe(n,"/etc/pam.d/common-password",`password required pam_unix.so obscure sha512
1075
- `),fe(n,"/etc/pam.d/common-session",`session required pam_unix.so
1076
- `),fe(n,"/etc/pam.d/sshd",`@include common-auth
1077
- @include common-account
1078
- @include common-session
1079
- `),ce(n,"/etc/sudoers.d"),fe(n,"/etc/sudoers",`root ALL=(ALL:ALL) ALL
1080
- %sudo ALL=(ALL:ALL) ALL
1081
- `,288),fe(n,"/etc/ld.so.conf",`include /etc/ld.so.conf.d/*.conf
1082
- `),ce(n,"/etc/ld.so.conf.d"),fe(n,"/etc/ld.so.conf.d/x86_64-linux-gnu.conf",`/lib/x86_64-linux-gnu
1083
- /usr/lib/x86_64-linux-gnu
1084
- `),fe(n,"/etc/locale.conf",`LANG=en_US.UTF-8
1085
- `),fe(n,"/etc/timezone",`UTC
1086
- `),fe(n,"/etc/localtime",`UTC
1087
- `)}function Lc(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(`
1088
- `)}
1089
- `);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(`
1090
- `)}
1091
- `);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(`
1092
- `)}
1093
- `,{mode:416})}function Qh(n){let t=n.match(/(\d+)$/);return 1e3+(t?.[1]?parseInt(t[1],10):0)}function Wh(n,t,e,r,s,i,o){let a=`/proc/${t}`;ce(n,a),ce(n,`${a}/fd`),ce(n,`${a}/fdinfo`);let c=Math.floor((Date.now()-new Date(i).getTime())/1e3),l=s.split(/\s+/)[0]??"bash";bt(n,`${a}/cmdline`,`${s.replace(/\s+/g,"\0")}\0`),bt(n,`${a}/comm`,l),bt(n,`${a}/status`,`${[`Name: ${l}`,"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(`
1094
- `)}
1095
- `),bt(n,`${a}/stat`,`${t} (${l}) S 1 ${t} ${t} 0 -1 4194304 0 0 0 0 ${c} 0 0 0 20 0 1 0 0 16384 4096 0
1096
- `),bt(n,`${a}/environ`,`${Object.entries(o).map(([f,u])=>`${f}=${u}`).join("\0")}\0`),bt(n,`${a}/cwd`,`/home/${e}\0`),bt(n,`${a}/exe`,"/bin/bash\0");for(let f of["0","1","2"])fe(n,`${a}/fd/${f}`,"")}function ME(n,t){ce(n,"/proc/boot"),fe(n,"/proc/boot/log",`${["[ 0.000000] Linux virtual kernel booting...","[ 0.000120] init memory subsystem","[ 0.000240] mount /proc /sys /dev","[ 0.000420] start init","[ 0.000680] system ready"].join(`
1097
- `)}
1098
- `),fe(n,"/proc/boot/version",`Linux ${t.kernel} (virtual)
1099
- `)}function Ao(n,t,e,r,s=[]){ce(n,"/proc");let i=Math.floor((Date.now()-r)/1e3),o=Math.floor(i*.9);bt(n,"/proc/uptime",`${i}.00 ${o}.00
1100
- `);let a=Math.floor(Sr.totalmem()/1024),c=Math.floor(Sr.freemem()/1024),l=Math.floor(c*.95);bt(n,"/proc/meminfo",`${[`MemTotal: ${String(a).padStart(10)} kB`,`MemFree: ${String(c).padStart(10)} kB`,`MemAvailable: ${String(l).padStart(10)} kB`,`Buffers: ${String(Math.floor(a*.02)).padStart(10)} kB`,`Cached: ${String(Math.floor(a*.15)).padStart(10)} kB`,`SwapTotal: ${String(Math.floor(a*.5)).padStart(10)} kB`,`SwapFree: ${String(Math.floor(a*.5)).padStart(10)} kB`].join(`
1101
- `)}
1102
- `);let f=Sr.cpus(),u=[];for(let x=0;x<f.length;x++){let B=f[x];B&&u.push(`processor : ${x}`,`model name : ${B.model}`,`cpu MHz : ${B.speed.toFixed(3)}`,"cache size : 8192 KB","")}bt(n,"/proc/cpuinfo",`${u.join(`
1103
- `)}
1104
- `),bt(n,"/proc/version",`Linux version ${t.kernel} (fortune@build) (gcc version 12.2.0) #1 SMP
1105
- `),bt(n,"/proc/hostname",`${e}
1106
- `);let h=(Math.random()*.5).toFixed(2),p=1+s.length;bt(n,"/proc/loadavg",`${h} ${h} ${h} ${p}/${p} 1
1107
- `),ce(n,"/proc/net"),fe(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(`
1108
- `)}
1109
- `),fe(n,"/proc/net/if_inet6",""),fe(n,"/proc/net/tcp",` sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode
1110
- `),fe(n,"/proc/net/tcp6",` sl local_address remote_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode
1111
- `),bt(n,"/proc/cmdline",`BOOT_IMAGE=/boot/vmlinuz-${t.kernel} root=/dev/sda2 ro quiet splash
1112
- `),fe(n,"/proc/filesystems",`${["nodev sysfs","nodev tmpfs","nodev proc","nodev devtmpfs"," ext4"," vfat","nodev squashfs","nodev overlay"].join(`
1113
- `)}
1114
- `);let A=`${["sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0","proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0","devtmpfs /dev devtmpfs rw,nosuid,size=8192k,nr_inodes=4096,mode=755 0 0","tmpfs /run tmpfs rw,nosuid,nodev,noexec,relatime,size=204800k,mode=755 0 0","tmpfs /tmp tmpfs rw,nosuid,nodev,noatime 0 0","/dev/sda2 / ext4 rw,relatime,errors=remount-ro 0 0","/dev/sda1 /boot ext4 rw,relatime 0 0","tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0","devpts /dev/pts devpts rw,nosuid,noexec,relatime,mode=620,ptmxmode=000 0 0","squashfs /snap/core squashfs ro,nodev,relatime 0 0"].join(`
1115
- `)}
1116
- `;bt(n,"/proc/mounts",A),ce(n,"/proc/self"),bt(n,"/proc/self/mounts",A),bt(n,"/proc/partitions",`${["major minor #blocks name",""," 8 0 41943040 sda"," 8 1 524288 sda1"," 8 2 41417216 sda2"," 7 0 10485760 loop0"].join(`
1117
- `)}
1118
- `),bt(n,"/proc/swaps",`Filename Type Size Used Priority
1119
- /dev/sda3 partition ${Math.floor(Sr.totalmem()/2048)} 0 -2
1120
- `),ce(n,"/proc/sys"),ce(n,"/proc/sys/kernel"),ce(n,"/proc/sys/net"),ce(n,"/proc/sys/vm"),fe(n,"/proc/sys/kernel/hostname",`${e}
1121
- `),fe(n,"/proc/sys/kernel/ostype",`Linux
1122
- `),fe(n,"/proc/sys/kernel/osrelease",`${t.kernel}
1123
- `),fe(n,"/proc/sys/kernel/pid_max",`32768
1124
- `),fe(n,"/proc/sys/kernel/threads-max",`65536
1125
- `),fe(n,"/proc/sys/kernel/randomize_va_space",`2
1126
- `),fe(n,"/proc/sys/kernel/dmesg_restrict",`0
1127
- `),fe(n,"/proc/sys/net/ipv4/ip_forward",`0
1128
- `),fe(n,"/proc/sys/vm/swappiness",`60
1129
- `),fe(n,"/proc/sys/vm/overcommit_memory",`0
1130
- `),Wh(n,1,"root","pts/0","/sbin/init",new Date(r).toISOString(),{});for(let x of s){let B=Qh(x.tty);Wh(n,B,x.username,x.tty,"bash",x.startedAt,{USER:x.username,HOME:`/home/${x.username}`,TERM:"xterm-256color",SHELL:"/bin/bash"})}let y=s.length>0?Qh(s[s.length-1].tty):1;if(n.exists("/proc/self"))try{n.remove("/proc/self")}catch{}let b=`/proc/${y}`;if(ce(n,"/proc/self"),ce(n,"/proc/self/fd"),n.exists(b))for(let x of n.list(b)){let B=`${b}/${x}`,H=`/proc/self/${x}`;try{n.stat(B).type==="file"&&bt(n,H,n.readFile(B))}catch{}}else bt(n,"/proc/self/cmdline","bash\0"),bt(n,"/proc/self/comm","bash"),bt(n,"/proc/self/status",`Name: bash
1131
- State: S (sleeping)
1132
- Pid: 1
1133
- PPid: 0
1134
- `),bt(n,"/proc/self/environ",""),bt(n,"/proc/self/cwd","/root\0"),bt(n,"/proc/self/exe","/bin/bash\0")}function UE(n,t,e){ce(n,"/sys"),ce(n,"/sys/devices"),ce(n,"/sys/devices/virtual"),ce(n,"/sys/devices/virtual/dmi"),ce(n,"/sys/devices/virtual/dmi/id");let r=LE(t),s=`VirtualNode-${(r%1e4).toString().padStart(4,"0")}`,i={bios_vendor:"Virtual BIOS",bios_version:"1.0",bios_date:"01/01/2025",sys_vendor:"Fortune Systems",product_name:s,product_family:"VirtualContainer",product_version:"v1",product_uuid:`${r.toString(16).padStart(8,"0")}-0000-0000-0000-000000000000`,product_serial:`SN-${r}`,chassis_type:"3",chassis_vendor:"Virtual",chassis_version:"v1",board_name:"fortune-board",modalias:`dmi:bvnVirtual:bvr1.0:svnFortune:pn${s}`};for(let[o,a]of Object.entries(i))fe(n,`/sys/devices/virtual/dmi/id/${o}`,`${a}
1135
- `);ce(n,"/sys/class"),ce(n,"/sys/class/net"),ce(n,"/sys/kernel"),fe(n,"/sys/kernel/hostname",`${t}
1136
- `),fe(n,"/sys/kernel/osrelease",`${e.kernel}
1137
- `),fe(n,"/sys/kernel/ostype",`Linux
1138
- `)}function $E(n){ce(n,"/dev"),fe(n,"/dev/null","",438),fe(n,"/dev/zero","",438),fe(n,"/dev/full","",438),fe(n,"/dev/random","",292),fe(n,"/dev/urandom","",292),fe(n,"/dev/mem","",416),fe(n,"/dev/console","",384),fe(n,"/dev/tty","",438),fe(n,"/dev/tty0","",400),fe(n,"/dev/tty1","",400),fe(n,"/dev/ttyS0","",432);for(let t=0;t<8;t++)fe(n,`/dev/loop${t}`,"",432);ce(n,"/dev/loop-control"),fe(n,"/dev/sda","",432),fe(n,"/dev/sda1","",432),fe(n,"/dev/sda2","",432),ce(n,"/dev/pts"),ce(n,"/dev/shm"),fe(n,"/dev/stdin","",438),fe(n,"/dev/stdout","",438),fe(n,"/dev/stderr","",438)}function FE(n){ce(n,"/usr"),ce(n,"/usr/bin"),ce(n,"/usr/sbin"),ce(n,"/usr/local"),ce(n,"/usr/local/bin"),ce(n,"/usr/local/lib"),ce(n,"/usr/local/share"),ce(n,"/usr/share"),ce(n,"/usr/share/doc"),ce(n,"/usr/share/man"),ce(n,"/usr/share/man/man1"),ce(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)fe(n,`/usr/bin/${e}`,`#!/bin/sh
1139
- exec builtin ${e} "$@"
1140
- `,493);fe(n,"/usr/bin/lsb_release",`#!/bin/sh
1141
- exec lsb_release "$@"
1142
- `,493)}function HE(n){ce(n,"/var"),ce(n,"/var/log"),ce(n,"/var/log/apt"),ce(n,"/var/tmp"),ce(n,"/var/cache"),ce(n,"/var/cache/apt"),ce(n,"/var/cache/apt/archives"),ce(n,"/var/lib"),ce(n,"/var/lib/apt"),ce(n,"/var/lib/apt/lists"),ce(n,"/var/lib/dpkg"),ce(n,"/var/lib/dpkg/info"),ce(n,"/var/lib/misc"),ce(n,"/var/spool"),ce(n,"/var/spool/cron"),ce(n,"/var/mail"),fe(n,"/var/lib/dpkg/status",""),fe(n,"/var/lib/dpkg/available",""),fe(n,"/var/log/syslog",`${new Date().toUTCString()} fortune kernel: Virtual container started
1143
- `),fe(n,"/var/log/auth.log",""),fe(n,"/var/log/kern.log",""),fe(n,"/var/log/dpkg.log",""),fe(n,"/var/log/apt/history.log",""),fe(n,"/var/log/apt/term.log",""),ce(n,"/run"),ce(n,"/run/lock"),ce(n,"/run/systemd"),ce(n,"/run/user"),fe(n,"/run/utmp","")}function QE(n){n.exists("/bin")||n.symlink("/usr/bin","/bin"),n.exists("/sbin")||n.symlink("/usr/sbin","/sbin"),n.exists("/var/run")||n.symlink("/run","/var/run"),ce(n,"/lib"),ce(n,"/lib64"),ce(n,"/lib/x86_64-linux-gnu"),ce(n,"/lib/modules")}function WE(n){ce(n,"/tmp",1023)}function qE(n){ce(n,"/root",448),fe(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(`
1144
- `)}
1145
- `),fe(n,"/root/.profile",`[ -f ~/.bashrc ] && . ~/.bashrc
1146
- `)}function KE(n,t){ce(n,"/opt"),ce(n,"/srv"),ce(n,"/mnt"),ce(n,"/media"),ce(n,"/home"),ce(n,"/boot"),ce(n,"/boot/grub"),ce(n,"/boot/grub/grub.cfg.d"),fe(n,"/boot/grub/grub.cfg",`${["# GRUB configuration (virtual)","set default=0","set timeout=5","",'menuentry "Fortune GNU/Linux" {'," linux /vmlinuz root=/dev/sda2 ro quiet splash"," initrd /initrd.img","}"].join(`
1147
- `)}
1148
- `);let e=t.kernel;fe(n,`/boot/vmlinuz-${e}`,"",420),fe(n,`/boot/initrd.img-${e}`,"",420),fe(n,`/boot/System.map-${e}`,`${e} virtual
1149
- `,420),fe(n,`/boot/config-${e}`,`# Linux kernel config ${e}
1150
- `,420),n.exists("/vmlinuz")||n.symlink(`/boot/vmlinuz-${e}`,"/vmlinuz"),n.exists("/vmlinuz.old")||n.symlink(`/boot/vmlinuz-${e}`,"/vmlinuz.old"),n.exists("/initrd.img")||n.symlink(`/boot/initrd.img-${e}`,"/initrd.img"),n.exists("/initrd.img.old")||n.symlink(`/boot/initrd.img-${e}`,"/initrd.img.old"),ce(n,"/snap"),ce(n,"/snap/bin"),ce(n,"/lost+found",448)}var qh=new Map;function VE(n,t){return`${n}|${t.kernel}|${t.os}|${t.arch}`}function zE(n,t){let e=VE(n,t),r=qh.get(e);if(r)return r;let s=new ji({mode:"memory"});DE(s,n,t),UE(s,n,t),$E(s),FE(s),HE(s),QE(s),WE(s),KE(s,t),ME(s,t);let i=s.encodeBinary();return qh.set(e,i),i}function Kh(n,t,e,r,s,i=[]){let o=zE(e,r);n.importRootTree(Er(o)),qE(n),Ao(n,r,e,s,i),Lc(n,t)}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
1151
- echo 'vim: use nano for editing in this environment'
1152
- `,mode:493},{path:"/usr/bin/vi",content:`#!/bin/sh
1153
- exec vim "$@"
1154
- `,mode:493},{path:"/usr/share/doc/vim/README",content:`Vim editor \u2014 virtual package.
1155
- `}]},{name:"git",version:"1:2.39.2-1",section:"vcs",description:"Fast, scalable, distributed revision control system",shortDesc:"fast distributed version control system",installedSizeKb:11240,files:[{path:"/usr/bin/git",content:`#!/bin/sh
1156
- echo 'git: virtual stub \u2014 no host access'
1157
- `,mode:493},{path:"/usr/share/doc/git/README.Debian",content:`Git virtual package for Fortune GNU/Linux.
1158
- `}]},{name:"python3",version:"3.11.2-1+b1",section:"python",description:"Interactive high-level object-oriented language (version 3)",shortDesc:"interactive high-level object-oriented language",installedSizeKb:512,depends:["python3-minimal"],files:[{path:"/usr/bin/python3",content:`#!/bin/sh
1159
- echo 'Python 3.11.2 (virtual)'
1160
- `,mode:493},{path:"/usr/bin/python3.11",content:`#!/bin/sh
1161
- exec python3 "$@"
1162
- `,mode:493},{path:"/usr/lib/python3.11/.keep",content:""}]},{name:"python3-minimal",version:"3.11.2-1+b1",section:"python",description:"Minimal subset of the Python language (version 3)",shortDesc:"minimal subset of Python language",installedSizeKb:196,files:[{path:"/usr/lib/python3-minimal/.keep",content:""}]},{name:"nodejs",version:"18.19.0+dfsg-6",section:"javascript",description:"Evented I/O for V8 javascript - runtime executable",shortDesc:"Node.js JavaScript runtime",installedSizeKb:15360,files:[{path:"/usr/bin/node",content:`#!/bin/sh
1163
- echo 'node v18.19.0 (virtual)'
1164
- `,mode:493},{path:"/usr/bin/nodejs",content:`#!/bin/sh
1165
- exec node "$@"
1166
- `,mode:493},{path:"/usr/share/doc/nodejs/README",content:`Node.js virtual package.
1167
- `}]},{name:"npm",version:"9.2.0~ds1-2",section:"javascript",description:"package manager for Node.js",shortDesc:"package manager for Node.js",installedSizeKb:9814,depends:["nodejs"],files:[{path:"/usr/bin/npm",content:`#!/bin/sh
1168
- exec builtin npm "$@"
1169
- `,mode:493},{path:"/usr/bin/npx",content:`#!/bin/sh
1170
- exec builtin npx "$@"
1171
- `,mode:493}]},{name:"curl",version:"7.88.1-10+deb12u5",section:"web",description:"command line tool for transferring data with URL syntax",shortDesc:"command line tool for transferring data",installedSizeKb:368,files:[{path:"/usr/bin/curl",content:`#!/bin/sh
1172
- exec builtin curl "$@"
1173
- `,mode:493}]},{name:"wget",version:"1.21.3-1+b2",section:"web",description:"Retrieves files from the web",shortDesc:"retrieves files from the web",installedSizeKb:952,files:[{path:"/usr/bin/wget",content:`#!/bin/sh
1174
- exec builtin wget "$@"
1175
- `,mode:493}]},{name:"htop",version:"3.2.2-2",section:"utils",description:"interactive processes viewer",shortDesc:"interactive process viewer",installedSizeKb:412,files:[{path:"/usr/bin/htop",content:`#!/bin/sh
1176
- exec builtin htop
1177
- `,mode:493}]},{name:"openssh-client",version:"1:9.2p1-2+deb12u2",section:"net",description:"Secure Shell (SSH) client",shortDesc:"secure shell (SSH) client",installedSizeKb:4540,files:[{path:"/usr/bin/ssh",content:`#!/bin/sh
1178
- echo 'ssh: virtual stub'
1179
- `,mode:493},{path:"/usr/bin/ssh-keygen",content:`#!/bin/sh
1180
- echo 'ssh-keygen: virtual stub'
1181
- `,mode:493},{path:"/etc/ssh/ssh_config",content:`Host *
1182
- StrictHostKeyChecking ask
1183
- `}]},{name:"openssh-server",version:"1:9.2p1-2+deb12u2",section:"net",description:"Secure Shell server (sshd)",shortDesc:"secure shell server",installedSizeKb:1732,depends:["openssh-client"],files:[{path:"/usr/sbin/sshd",content:`#!/bin/sh
1184
- echo 'sshd: virtual \u2014 server already running'
1185
- `,mode:493},{path:"/etc/ssh/sshd_config",content:`Port 22
1186
- PermitRootLogin yes
1187
- PasswordAuthentication yes
1188
- `}]},{name:"net-tools",version:"2.10-0.1",section:"net",description:"NET-3 networking toolkit (ifconfig, netstat, route)",shortDesc:"networking toolkit",installedSizeKb:988,files:[{path:"/usr/bin/ifconfig",content:`#!/bin/sh
1189
- echo 'eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500'
1190
- echo ' inet 10.0.0.2 netmask 255.255.255.0 broadcast 10.0.0.255'
1191
- echo ' ether 02:42:0a:00:00:02 txqueuelen 0 (Ethernet)'
1192
- `,mode:493},{path:"/usr/bin/netstat",content:`#!/bin/sh
1193
- echo 'Active Internet connections (only servers)'
1194
- echo 'Proto Recv-Q Send-Q Local Address Foreign Address State'
1195
- `,mode:493},{path:"/usr/bin/route",content:`#!/bin/sh
1196
- echo 'Kernel IP routing table'
1197
- echo 'Destination Gateway Genmask Flags Metric Ref Use Iface'
1198
- echo '0.0.0.0 10.0.0.1 0.0.0.0 UG 0 0 0 eth0'
1199
- `,mode:493}]},{name:"iputils-ping",version:"3:20221126-1",section:"net",description:"Tools to test the reachability of network hosts",shortDesc:"test reachability of network hosts",installedSizeKb:164,files:[{path:"/usr/bin/ping",content:`#!/bin/sh
1200
- exec builtin ping "$@"
1201
- `,mode:493}]},{name:"jq",version:"1.6-2.1",section:"utils",description:"Lightweight and flexible command-line JSON processor",shortDesc:"command-line JSON processor",installedSizeKb:296,files:[{path:"/usr/bin/jq",content:`#!/bin/sh
1202
- echo 'jq: virtual stub \u2014 pipe JSON here'
1203
- `,mode:493}]},{name:"build-essential",version:"12.9",section:"devel",description:"Informational list of build-essential packages",shortDesc:"build-essential meta-package",installedSizeKb:12,depends:["gcc","g++","make"],files:[{path:"/usr/share/doc/build-essential/README",content:`Build-essential virtual meta-package.
1204
- `}]},{name:"gcc",version:"4:12.2.0-3",section:"devel",description:"GNU C compiler",shortDesc:"GNU C compiler",installedSizeKb:24448,files:[{path:"/usr/bin/gcc",content:`#!/bin/sh
1205
- echo 'gcc (Fortune GNU/Linux) 12.2.0 (virtual)'
1206
- `,mode:493},{path:"/usr/bin/gcc-12",content:`#!/bin/sh
1207
- exec gcc "$@"
1208
- `,mode:493}]},{name:"g++",version:"4:12.2.0-3",section:"devel",description:"GNU C++ compiler",shortDesc:"GNU C++ compiler",installedSizeKb:1024,depends:["gcc"],files:[{path:"/usr/bin/g++",content:`#!/bin/sh
1209
- echo 'g++ (Fortune GNU/Linux) 12.2.0 (virtual)'
1210
- `,mode:493}]},{name:"make",version:"4.3-4.1",section:"devel",description:"Utility for directing compilation",shortDesc:"build utility",installedSizeKb:504,files:[{path:"/usr/bin/make",content:`#!/bin/sh
1211
- echo 'make: *** No targets specified and no makefile found. Stop.'
1212
- exit 2
1213
- `,mode:493}]},{name:"less",version:"590-2",section:"text",description:"Pager program similar to more",shortDesc:"pager program",installedSizeKb:328,files:[{path:"/usr/bin/less",content:`#!/bin/sh
1214
- cat "$@"
1215
- `,mode:493}]},{name:"unzip",version:"6.0-28",section:"utils",description:"De-archiver for .zip files",shortDesc:"de-archiver for .zip files",installedSizeKb:464,files:[{path:"/usr/bin/unzip",content:`#!/bin/sh
1216
- echo 'unzip: virtual stub'
1217
- `,mode:493}]},{name:"rsync",version:"3.2.7-1",section:"net",description:"Fast, versatile, remote (and local) file-copying tool",shortDesc:"fast remote file copy program",installedSizeKb:716,files:[{path:"/usr/bin/rsync",content:`#!/bin/sh
1218
- echo 'rsync: virtual stub'
1219
- `,mode:493}]},{name:"tmux",version:"3.3a-3",section:"utils",description:"Terminal multiplexer",shortDesc:"terminal multiplexer",installedSizeKb:812,files:[{path:"/usr/bin/tmux",content:`#!/bin/sh
1220
- echo 'tmux: terminal multiplexer (virtual stub)'
1221
- `,mode:493}]},{name:"tree",version:"2.1.0-1",section:"utils",description:"Displays an indented directory tree, in color",shortDesc:"list files in tree format",installedSizeKb:108,files:[{path:"/usr/bin/tree",content:`#!/bin/sh
1222
- exec builtin tree "$@"
1223
- `,mode:493}]},{name:"ca-certificates",version:"20230311",section:"misc",description:"Common CA certificates",shortDesc:"common CA certificates",installedSizeKb:388,files:[{path:"/etc/ssl/certs/.keep",content:""},{path:"/etc/ssl/private/.keep",content:""},{path:"/usr/share/ca-certificates/.keep",content:""}],onInstall:n=>{n.exists("/etc/ssl")||n.mkdir("/etc/ssl",493),n.exists("/etc/ssl/certs")||n.mkdir("/etc/ssl/certs",493)}},{name:"locales",version:"2.36-9+deb12u3",section:"localization",description:"GNU C Library: National Language (locale) data",shortDesc:"locale data",installedSizeKb:16484,files:[{path:"/etc/locale.gen",content:`en_US.UTF-8 UTF-8
1224
- `},{path:"/etc/default/locale",content:`LANG=en_US.UTF-8
1225
- LANGUAGE=en_US:en
1226
- `}]},{name:"sudo",version:"1.9.13p3-1+deb12u1",section:"admin",description:"Provide limited super user privileges to specific users",shortDesc:"super user privilege execution",installedSizeKb:2304,files:[{path:"/usr/bin/sudo",content:`#!/bin/sh
1227
- exec builtin sudo "$@"
1228
- `,mode:493},{path:"/etc/sudoers",content:`root ALL=(ALL:ALL) ALL
1229
- %sudo ALL=(ALL:ALL) ALL
1230
- `}]},{name:"systemd",version:"252.22-1~deb12u1",section:"admin",description:"System and service manager",shortDesc:"system and service manager",installedSizeKb:26624,files:[{path:"/usr/bin/systemctl",content:`#!/bin/sh
1231
- echo 'systemd is not running in this virtual container.'
1232
- exit 1
1233
- `,mode:493},{path:"/usr/bin/journalctl",content:`#!/bin/sh
1234
- echo 'journalctl: virtual stub'
1235
- `,mode:493}]},{name:"gzip",version:"1.12-2",section:"utils",description:"GNU compression utility",shortDesc:"compression utility",installedSizeKb:128,files:[{path:"/usr/bin/gzip",content:`#!/bin/sh
1236
- echo 'gzip: virtual stub'
1237
- `,mode:493}]},{name:"neofetch",version:"7.1.0-1",section:"utils",description:"A command-line system information tool written in bash 3.2+",shortDesc:"command-line system information tool",installedSizeKb:256,files:[{path:"/usr/bin/neofetch",content:`#!/bin/sh
1238
- echo 'neofetch: virtual stub'
1239
- `,mode:493}]}],Xi=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(`
1240
- `));this.vfs.writeFile(this.registryPath,`${t.join(`
1241
-
1242
- `)}
1243
- `)}parseFields(t){let e={};for(let r of t.split(`
1244
- `)){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}
1245
- `,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(`
1246
- `);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,l=new Set)=>{if(l.has(c)||(l.add(c),this.isInstalled(c)))return;let f=this.findInRegistry(c);if(!f){i.push(c);return}for(let u of f.depends??[])o(u,l);s.find(u=>u.name===f.name)||s.push(f)};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(`
1247
- `),exitCode:0};let a=s.reduce((c,l)=>c+(l.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 f of c.files??[]){let u=f.path.slice(0,f.path.lastIndexOf("/"));u&&!this.vfs.exists(u)&&this.vfs.mkdir(u,493),this.vfs.writeFile(f.path,f.content,{mode:f.mode??420})}c.onInstall?.(this.vfs,this.users),e.quiet||r.push(`Setting up ${c.name} (${c.version}) ...`);let l=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:l,files:(c.files??[]).map(f=>f.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(`
1248
- `),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(`
1249
- `)||"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(`
1250
- `),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(`
1251
- `)}};var Cn=require("node:crypto"),zh=require("node:events"),Yh=Wt(require("node:path"),1);function YE(){let n=process.env.SSH_MIMIC_FAST_PASSWORD_HASH;return!!n&&!["0","false","no","off"].includes(n.toLowerCase())}var Ot=mn("VirtualUserManager"),Ji=class n extends zh.EventEmitter{constructor(e,r=!0){super();this.vfs=e;this.autoSudoForNewUsers=r;Ot.mark("constructor")}vfs;autoSudoForNewUsers;static recordCache=new Map;static fastPasswordHash=YE();usersPath="/etc/htpasswd";sudoersPath="/etc/sudoers";quotasPath="/etc/quotas";authDirPath="/.virtual-env-js/.auth";users=new Map;sudoers=new Set;quotas=new Map;activeSessions=new Map;nextTty=0;async initialize(){Ot.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(Ot.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){Ot.mark("clearQuota"),this.validateUsername(e),this.quotas.delete(e),await this.persist()}getQuotaBytes(e){return Ot.mark("getQuotaBytes"),this.quotas.get(e)??null}getUsageBytes(e){Ot.mark("getUsageBytes");let r=`/home/${e}`;return this.vfs.exists(r)?this.vfs.getUsageBytes(r):0}assertWriteWithinQuota(e,r,s){Ot.mark("assertWriteWithinQuota");let i=this.quotas.get(e);if(i===void 0)return;let o=Vh(r),a=Vh(`/home/${e}`);if(!(o===a||o.startsWith(`${a}/`)))return;let l=this.getUsageBytes(e),f=0;if(this.vfs.exists(o)){let p=this.vfs.stat(o);p.type==="file"&&(f=p.size)}let u=Buffer.isBuffer(s)?s.length:Buffer.byteLength(s,"utf8"),h=l-f+u;if(h>i)throw new Error(`quota exceeded for '${e}': ${h}/${i} bytes`)}verifyPassword(e,r){Ot.mark("verifyPassword");let s=this.users.get(e);if(!s)return this.hashPassword(r,""),!1;let i=this.hashPassword(r,s.salt),o=s.passwordHash;try{let a=Buffer.from(i,"hex"),c=Buffer.from(o,"hex");return a.length!==c.length?!1:(0,Cn.timingSafeEqual)(a,c)}catch{return i===o}}async addUser(e,r){if(Ot.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){Ot.mark("getPasswordHash");let r=this.users.get(e);return r?r.passwordHash:null}async setPassword(e,r){if(Ot.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(Ot.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 Ot.mark("isSudoer"),this.sudoers.has(e)}async addSudoer(e){if(Ot.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(Ot.mark("removeSudoer"),this.validateUsername(e),e==="root")throw new Error("sudoers: cannot remove root");this.sudoers.delete(e),await this.persist()}registerSession(e,r){Ot.mark("registerSession");let s={id:(0,Cn.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(Ot.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(Ot.mark("updateSession"),!e)return;let i=this.activeSessions.get(e);i&&this.activeSessions.set(e,{...i,username:r,remoteAddress:s})}listActiveSessions(){return Ot.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(`
1252
- `)){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(`
1253
- `)){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(`
1254
- `)){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(`
1255
- `),r=Array.from(this.sudoers.values()).sort().join(`
1256
- `),s=Array.from(this.quotas.entries()).sort(([o],[a])=>o.localeCompare(a)).map(([o,a])=>`${o}:${a}`).join(`
1257
- `),i=!1;i=this.writeIfChanged(this.usersPath,e.length>0?`${e}
1258
- `:"",384)||i,i=this.writeIfChanged(this.sudoersPath,r.length>0?`${r}
1259
- `:"",384)||i,i=this.writeIfChanged(this.quotasPath,s.length>0?`${s}
1260
- `:"",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=(0,Cn.createHash)("sha256").update(e).update(":").update(r).digest("hex"),i=n.recordCache.get(s);if(i)return i;let o=(0,Cn.randomBytes)(16).toString("hex"),a={username:e,salt:o,passwordHash:this.hashPassword(r,o)};return n.recordCache.set(s,a),a}hasPassword(e){Ot.mark("hasPassword");let r=this.users.get(e);if(!r)return!1;let s=this.hashPassword("",r.salt);return r.passwordHash===s?!1:!!r.passwordHash}hashPassword(e,r=""){return n.fastPasswordHash?(0,Cn.createHash)("sha256").update(r).update(e).digest("hex"):(0,Cn.scryptSync)(e,r||"",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){Ot.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 Vh(n){let t=Yh.posix.normalize(n);return t.startsWith("/")?t:`/${t}`}var Gh=require("node:events");var Zi=class extends Gh.EventEmitter{vfs;idleThresholdMs;checkIntervalMs;_state="active";_lastActivity=Date.now();_frozenBuffer=null;_checkTimer=null;constructor(t,e={}){super(),this.vfs=t,this.idleThresholdMs=e.idleThresholdMs??6e4,this.checkIntervalMs=e.checkIntervalMs??15e3}start(){this._checkTimer||(this._lastActivity=Date.now(),this._checkTimer=setInterval(()=>this._check(),this.checkIntervalMs),typeof this._checkTimer=="object"&&this._checkTimer!==null&&"unref"in this._checkTimer&&this._checkTimer.unref())}async stop(){this._checkTimer&&(clearInterval(this._checkTimer),this._checkTimer=null),this._state==="frozen"&&this._thaw()}ping(){this._lastActivity=Date.now(),this._state==="frozen"&&this._thaw()}get state(){return this._state}get idleMs(){return Date.now()-this._lastActivity}_check(){this._state!=="frozen"&&Date.now()-this._lastActivity>=this.idleThresholdMs&&this._freeze()}async _freeze(){this._state!=="frozen"&&(await this.vfs.stopAutoFlush(),this._frozenBuffer=this.vfs.encodeBinary(),this.vfs.releaseTree(),this._state="frozen",this.emit("freeze"))}_thaw(){if(this._state!=="frozen"||!this._frozenBuffer)return;let t=Er(this._frozenBuffer);this.vfs.importRootTree(t),this._frozenBuffer=null,this._state="active",this.emit("thaw")}};var ri=require("node:fs/promises"),Uc=Wt(require("node:path"),1);var tp=require("node:child_process");var jh=require("node:fs/promises"),Eo=Wt(require("node:path"),1);function Mc(n){return`'${n.replace(/'/g,"'\\''")}'`}function es(n){return n.replace(/\r\n/g,`
1261
- `).replace(/\r/g,`
1262
- `).replace(/\n/g,`\r
1263
- `)}function Xh(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 Jh(n,t){return!t||t.trim()===""||t==="."?n:t.startsWith("/")?Eo.posix.normalize(t):Eo.posix.normalize(Eo.posix.join(n,t))}async function Zh(n){try{let e=(await(0,jh.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=>Zh(s)));return[...e,...r.flat()]}catch{return[]}}async function ep(n=process.pid){let t=await Zh(n),e=Array.from(new Set(t)).sort((r,s)=>r-s);return e.length===0?null:e.join(",")}function np(n,t,e){let r=Xh(n,t),s=(0,tp.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 rp(n,t,e){return np(`nano -- ${Mc(n)}`,t,e)}function ip(n,t,e){return np(`htop -p ${Mc(n)}`,t,e)}function sp(n,t,e){let r=[`Linux ${n} ${t.kernel} ${t.arch}`,"","The programs included with the Fortune GNU/Linux system are free software;","the exact distribution terms for each program are described in the","individual files in /usr/share/doc/*/copyright.","","Fortune GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent","permitted by applicable law."];if(e){let s=new Date(e.at),i=Number.isNaN(s.getTime())?e.at:ys(s);r.push(`Last login: ${i} from ${e.from||"unknown"}`)}return r.push(""),`${r.map(s=>`${s}\r
1264
- `).join("")}`}function op(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 ap(n,t,e,r,s,i="unknown",o={cols:80,rows:24},a){let c="",l=0,f=GE(a.vfs,e),u=null,h="",p=`/home/${e}`,A=Lr(e,r),y=null,b=null,x=()=>{let R=`/home/${e}`,O=p===R?"~":Uc.posix.basename(p)||"/";return op(e,r,O)},B=Array.from(new Set(Mo())).sort();console.log(`[${s}] Shell started for user '${e}' at ${i}`),(async()=>{let R=`/home/${e}/.bashrc`;if(a.vfs.exists(R))try{let O=a.vfs.readFile(R);for(let K of O.split(`
1265
- `)){let ee=K.trim();!ee||ee.startsWith("#")||await xt(ee,e,r,"shell",p,a,void 0,A)}}catch{}})();function H(){let R=x();t.write(`\r${R}${c}\x1B[K`);let O=c.length-l;O>0&&t.write(`\x1B[${O}D`)}function C(){t.write("\r\x1B[K")}function M(R){b={...R,buffer:""},C(),t.write(R.prompt)}async function Q(R){if(!b)return;let O=b;if(b=null,!R){t.write(`\r
1266
- Sorry, try again.\r
1267
- `),H();return}if(!O.commandLine){e=O.targetUser,O.loginShell&&(p=`/home/${e}`),a.users.updateSession(s,e,i),t.write(`\r
1268
- `),H();return}let K=O.loginShell?`/home/${O.targetUser}`:p,ee=await Promise.resolve(xt(O.commandLine,O.targetUser,r,"shell",K,a));if(t.write(`\r
1269
- `),ee.openEditor){await S(ee.openEditor.targetPath,ee.openEditor.initialContent,ee.openEditor.tempPath);return}if(ee.openHtop){await w();return}ee.clearScreen&&t.write("\x1B[2J\x1B[H"),ee.stdout&&t.write(`${es(ee.stdout)}\r
1270
- `),ee.stderr&&t.write(`${es(ee.stderr)}\r
1271
- `),ee.switchUser?(e=ee.switchUser,p=ee.nextCwd??`/home/${e}`,a.users.updateSession(s,e,i)):ee.nextCwd&&(p=ee.nextCwd),H()}async function N(){if(!y)return;let R=y;if(R.kind==="nano"){try{let O=await(0,ri.readFile)(R.tempPath,"utf8");a.writeFileAsUser(e,R.targetPath,O)}catch{}await(0,ri.unlink)(R.tempPath).catch(()=>{})}y=null,c="",l=0,t.write(`\r
1272
- `),H()}async function S(R,O,K){a.vfs.exists(R)&&await(0,ri.writeFile)(K,O,"utf8");let ee=rp(K,o,t);ee.on("error",ue=>{t.write(`nano: ${ue.message}\r
1273
- `),N()}),ee.on("close",()=>{N()}),y={kind:"nano",targetPath:R,tempPath:K,process:ee}}async function w(){let R=await ep();if(!R){t.write(`htop: no child_process processes to display\r
1274
- `);return}let O=ip(R,o,t);O.on("error",K=>{t.write(`htop: ${K.message}\r
1275
- `),N()}),O.on("close",()=>{N()}),y={kind:"htop",targetPath:"",tempPath:"",process:O}}function v(R){c=R,l=c.length,H()}function k(R){c=`${c.slice(0,l)}${R}${c.slice(l)}`,l+=R.length,H()}function P(R,O){let K=O;for(;K>0&&!/\s/.test(R[K-1]);)K-=1;let ee=O;for(;ee<R.length&&!/\s/.test(R[ee]);)ee+=1;return{start:K,end:ee}}function ne(R){let O=R.lastIndexOf("/"),K=O>=0?R.slice(0,O+1):"",ee=O>=0?R.slice(O+1):R,ue=Jh(p,K||".");try{return a.vfs.list(ue).filter(ie=>!ie.startsWith(".")).filter(ie=>ie.startsWith(ee)).map(ie=>{let Xe=Uc.posix.join(ue,ie),cn=a.vfs.stat(Xe).type==="directory"?"/":"";return`${K}${ie}${cn}`}).sort()}catch{return[]}}function Y(){let{start:R,end:O}=P(c,l),K=c.slice(R,l);if(K.length===0)return;let ue=c.slice(0,R).trim().length===0?B.filter(dt=>dt.startsWith(K)):[],ie=ne(K),Xe=Array.from(new Set([...ue,...ie])).sort();if(Xe.length!==0){if(Xe.length===1){let dt=Xe[0],cn=dt.endsWith("/")?"":" ";c=`${c.slice(0,R)}${dt}${cn}${c.slice(O)}`,l=R+dt.length+cn.length,H();return}t.write(`\r
1276
- `),t.write(`${Xe.join(" ")}\r
1277
- `),H()}}function G(R){if(R.length===0)return;f.push(R),f.length>500&&(f=f.slice(f.length-500));let O=f.length>0?`${f.join(`
1278
- `)}
1279
- `:"";a.vfs.writeFile(`/home/${e}/.bash_history`,O)}function te(){let R=`/home/${e}/.lastlog.json`;if(!a.vfs.exists(R))return null;try{return JSON.parse(a.vfs.readFile(R))}catch{return null}}function le(R){let O=`/home/${e}/.lastlog`;a.vfs.writeFile(O,JSON.stringify({at:R,from:i}))}function U(){let R=te(),O=new Date().toISOString();t.write(sp(r,n,R)),le(O)}U(),H(),t.on("data",async R=>{if(y){y.process.stdin.write(R);return}if(b){let K=R.toString("utf8");for(let ee=0;ee<K.length;ee+=1){let ue=K[ee];if(ue===""){b=null,t.write(`^C\r
1280
- `),H();return}if(ue==="\x7F"||ue==="\b"){b.buffer=b.buffer.slice(0,-1);continue}if(ue==="\r"||ue===`
1281
- `){let ie=b.buffer;if(b.buffer="",b.onPassword){let{result:dt,nextPrompt:cn}=await b.onPassword(ie,a);t.write(`\r
1282
- `),dt!==null?(b=null,dt.stdout&&t.write(dt.stdout.replace(/\n/g,`\r
1283
- `)),dt.stderr&&t.write(dt.stderr.replace(/\n/g,`\r
1284
- `)),H()):(cn&&(b.prompt=cn),t.write(b.prompt));return}let Xe=a.users.verifyPassword(b.username,ie);await Q(Xe);return}ue>=" "&&(b.buffer+=ue)}return}let O=R.toString("utf8");for(let K=0;K<O.length;K+=1){let ee=O[K];if(ee===""){c="",l=0,u=null,h="",t.write(`bye\r
1285
- `),G("bye"),t.write(`logout\r
1286
- `),t.exit(0),t.end();return}if(ee===" "){Y();continue}if(ee==="\x1B"){let ue=O[K+1],ie=O[K+2],Xe=O[K+3];if(ue==="["&&ie){if(ie==="A"){K+=2,f.length>0&&(u===null?(h=c,u=f.length-1):u>0&&(u-=1),v(f[u]??""));continue}if(ie==="B"){K+=2,u!==null&&(u<f.length-1?(u+=1,v(f[u]??"")):(u=null,v(h)));continue}if(ie==="C"){K+=2,l<c.length&&(l+=1,t.write("\x1B[C"));continue}if(ie==="D"){K+=2,l>0&&(l-=1,t.write("\x1B[D"));continue}if(ie==="3"&&Xe==="~"){K+=3,l<c.length&&(c=`${c.slice(0,l)}${c.slice(l+1)}`,H());continue}}}if(ee===""){c="",l=0,u=null,h="",t.write(`^C\r
1287
- `),H();continue}if(ee==="\r"||ee===`
1288
- `){let ue=c.trim();if(c="",l=0,u=null,h="",t.write(`\r
1289
- `),ue.length>0){let ie=await Promise.resolve(xt(ue,e,r,"shell",p,a,void 0,A));if(G(ue),ie.openEditor){await S(ie.openEditor.targetPath,ie.openEditor.initialContent,ie.openEditor.tempPath);return}if(ie.openHtop){await w();return}if(ie.sudoChallenge){M(ie.sudoChallenge);return}if(ie.clearScreen&&t.write("\x1B[2J\x1B[H"),ie.stdout&&t.write(`${es(ie.stdout)}\r
1290
- `),ie.stderr&&t.write(`${es(ie.stderr)}\r
1291
- `),ie.closeSession){t.write(`logout\r
1292
- `),t.exit(ie.exitCode??0),t.end();return}ie.nextCwd&&(p=ie.nextCwd),ie.switchUser&&(e=ie.switchUser,p=ie.nextCwd??`/home/${e}`,a.users.updateSession(s,e,i),c="",l=0)}H();continue}if(ee==="\x7F"||ee==="\b"){l>0&&(c=`${c.slice(0,l-1)}${c.slice(l)}`,l-=1,H());continue}k(ee)}}),t.on("close",()=>{y&&(y.process.kill("SIGTERM"),y=null)})}function GE(n,t){let e=`/home/${t}/.bash_history`;return n.exists(e)?n.readFile(e).split(`
1293
- `).map(s=>s.trim()).filter(s=>s.length>0):(n.writeFile(e,""),[])}function jE(n){return typeof n=="object"&&n!==null&&"vfsInstance"in n&&lp(n.vfsInstance)}function lp(n){if(typeof n!="object"||n===null)return!1;let t=n;return typeof t.restoreMirror=="function"&&typeof t.flushMirror=="function"&&typeof t.writeFile=="function"&&typeof t.readFile=="function"&&typeof t.mkdir=="function"&&typeof t.exists=="function"&&typeof t.stat=="function"&&typeof t.list=="function"&&typeof t.remove=="function"&&typeof t.copy=="function"&&typeof t.move=="function"&&typeof t.touch=="function"}var XE={kernel:"1.0.0+itsrealfortune+1-amd64",os:"Fortune GNU/Linux x64",arch:"x86_64"},ts=mn("VirtualShell");function JE(){let n=process.env.SSH_MIMIC_AUTO_SUDO_NEW_USERS;return n?!["0","false","no","off"].includes(n.toLowerCase()):!0}var zn=class extends cp.EventEmitter{vfs;users;packageManager;hostname;properties;startTime;_idle=null;initialized;constructor(t,e,r){super(),ts.mark("constructor"),this.hostname=t,this.properties=e||XE,this.startTime=Date.now(),lp(r)?this.vfs=r:jE(r)?this.vfs=r.vfsInstance:this.vfs=new ji(r??{}),this.users=new Ji(this.vfs,JE()),this.packageManager=new Xi(this.vfs,this.users);let s=this.vfs,i=this.users,o=this.packageManager,a=this.properties,c=this.hostname,l=this.startTime;this.initialized=(async()=>{await s.restoreMirror(),await i.initialize(),Kh(s,i,c,a,l),o.load(),this.emit("initialized")})()}async ensureInitialized(){ts.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");Lo(Do(s,e,r))}executeCommand(t,e,r){ts.mark("executeCommand"),this._idle?.ping(),xt(t,e,this.hostname,"shell",r,this),this.emit("command",{command:t,user:e,cwd:r})}startInteractiveSession(t,e,r,s,i){ts.mark("startInteractiveSession"),this._idle?.ping(),this.emit("session:start",{user:e,sessionId:r,remoteAddress:s}),ap(this.properties,t,e,this.hostname,r,s,i,this),this.refreshProcSessions()}refreshProcFs(){Ao(this.vfs,this.properties,this.hostname,this.startTime,this.users.listActiveSessions())}mount(t,e,r={}){this.vfs.mount(t,e,r)}unmount(t){this.vfs.unmount(t)}getMounts(){return this.vfs.getMounts()}refreshProcSessions(){Ao(this.vfs,this.properties,this.hostname,this.startTime,this.users.listActiveSessions())}syncPasswd(){Lc(this.vfs,this.users)}getVfs(){return this?.vfs??null}getUsers(){return this?.users??null}getHostname(){return this?.hostname}writeFileAsUser(t,e,r){ts.mark("writeFileAsUser"),this.users.assertWriteWithinQuota(t,e,r),this.vfs.writeFile(e,r)}enableIdleManagement(t){this._idle||(this._idle=new Zi(this.vfs,t),this._idle.on("freeze",()=>this.emit("shell:freeze")),this._idle.on("thaw",()=>this.emit("shell:thaw")),this._idle.start())}async disableIdleManagement(){this._idle&&(await this._idle.stop(),this._idle=null)}get idleState(){return this._idle?.state??"active"}get idleMs(){return this._idle?.idleMs??0}pingIdle(){this._idle?.ping()}};function fp(n){return n.replace(/\r\n/g,`
1294
- `).replace(/\r/g,`
1295
- `).replace(/\n/g,`\r
1296
- `)}function up(n,t,e,r,s){Promise.resolve(xt(t,e,r,"exec",`/home/${e}`,s,void 0,Lr(e,r))).then(i=>{i.stdout&&n.write(`${fp(i.stdout)}\r
1297
- `),i.stderr&&n.stderr.write(`${fp(i.stderr)}\r
1298
- `),n.exit(i.exitCode??0),n.end()}).catch(i=>{console.error("Exec error:",i),n.stderr.write(`Error: ${String(i)}\r
1299
- `),n.exit(1),n.end()})}var dp=require("node:crypto"),cr=require("node:fs"),yo=require("node:path");function _o(n=process.cwd()){let t=(0,yo.resolve)(n,".ssh-mimic","host_rsa");if((0,cr.existsSync)(t))return(0,cr.readFileSync)(t,"utf8");let e=(0,dp.generateKeyPairSync)("rsa",{modulusLength:2048,privateKeyEncoding:{type:"pkcs1",format:"pem"},publicKeyEncoding:{type:"pkcs1",format:"pem"}}).privateKey;return(0,cr.mkdirSync)((0,yo.dirname)(t),{recursive:!0}),(0,cr.writeFileSync)(t,e,{mode:384}),e}var hp=require("node:events"),oi=Wt(require("node:path"),1),pp=Wt(vc(),1);var Fc=!!process.env.DEV_MODE,ii=Fc?console.log.bind(console):()=>{},On=Fc?console.warn.bind(console):()=>{},ns=Fc?console.error.bind(console):()=>{},He={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},si={READ:1,WRITE:2,APPEND:4,CREAT:8,TRUNC:16,EXCL:32},$c=mn("SftpMimic"),ai=class extends hp.EventEmitter{port;server;hostname;shell;vfs;users;nextHandleId=0;handles=new Map;constructor({port:t,hostname:e="typescript-vm",shell:r,vfs:s,users:i}){if(super(),$c.mark("constructor"),this.port=t,this.server=null,this.hostname=e,this.shell=null,r)this.vfs=r.vfs,this.users=r.users,this.hostname=r.hostname,this.shell=r;else if(s&&i)this.vfs=s,this.users=i;else{let o=new zn(e);this.vfs=o.vfs,this.users=o.users,this.shell=o}}getVfs(){return this.shell?.vfs??this.vfs}getUsers(){return this.shell?.users??this.users}async start(){$c.mark("start");let t=_o();return this.shell?await this.shell.ensureInitialized():await this.users.initialize(),this.server=new pp.Server({hostKeys:[t],ident:`SSH-2.0-${this.hostname}`},e=>{let r=["password","keyboard-interactive"],s="root",i=null,o="unknown";this.emit("client:connect"),e.on("error",c=>{ns("[SFTP] Client error:",c)});let a=c=>{s=c,i=this.getUsers().registerSession(s,o).id;let l="/home";this.getVfs().exists(l)||this.getVfs().mkdir(l,493);let f=`/home/${s}`;this.getVfs().exists(f)||(this.getVfs().mkdir(f,493),this.getVfs().writeFile(`${f}/README.txt`,`Welcome to ${this.hostname}`))};e.on("authentication",c=>{let l=c.username||"root";if(o=c.ip??o,ii(`[SFTP] Auth attempt: user=${l}, method=${c.method}, ip=${o}`),c.method==="password"){if(!this.getUsers().hasPassword(l)){a(l),this.emit("auth:success",{username:s,remoteAddress:o}),c.accept();return}if(!this.getUsers().verifyPassword(l,c.password??"")){this.emit("auth:failure",{username:l,remoteAddress:o}),c.reject(r);return}a(l),this.emit("auth:success",{username:s,remoteAddress:o}),c.accept();return}if(c.method==="keyboard-interactive"){let f=c;if(!this.getUsers().hasPassword(l)){a(l),this.emit("auth:success",{username:s,remoteAddress:o}),f.accept();return}f.prompt([{prompt:"Password: ",echo:!1}],u=>{let h=u[0]??"";if(!this.getUsers().verifyPassword(l,h)){this.emit("auth:failure",{username:l,remoteAddress:o}),f.reject(r);return}a(l),this.emit("auth:success",{username:s,remoteAddress:o}),f.accept()});return}c.reject(r)}),e.on("close",()=>{this.getUsers().unregisterSession(i),this.emit("client:disconnect",{user:s}),i=null}),e.on("ready",()=>{e.on("session",(c,l)=>{let f=c();f.on("error",u=>{ns(`[SFTP] Session error for user=${s}:`,u)}),f.on("sftp",u=>{let h=u();this.attachSftpHandlers(h,s)})})})}),new Promise((e,r)=>{this.server?.once("error",s=>r(s)),this.server?.listen(this.port,"0.0.0.0",()=>{let s=this.server?.address(),i=s&&typeof s=="object"&&"port"in s?s.port:this.port;ii(`SFTP Mimic listening on port ${i}`),this.emit("start",{port:i}),e(i)})})}stop(){$c.mark("stop"),this.server&&this.server.close(()=>{ii("SFTP Mimic stopped"),this.emit("stop")})}resolveRequestPath(t,e){let r=`/home/${e}`;if(!t||t===".")return r;if(!t.startsWith("/")){let s=oi.posix.join(r,t);return oi.posix.normalize(s)}return oi.posix.normalize(t)}isPathWithinHome(t,e){let r=`/home/${e}`,s=oi.posix.normalize(t);return!!(s===r||s.startsWith(`${r}/`))}createAttrs(t){let e=t.mode&511;return{mode:(t.type==="directory"?16384:32768)|e,size:t.type==="file"?t.size:0,uid:0,gid:0,atime:Math.floor(t.createdAt.getTime()/1e3),mtime:Math.floor(t.updatedAt.getTime()/1e3)}}openHandle(t){let e=++this.nextHandleId,r=Buffer.alloc(4);return r.writeUInt32BE(e,0),this.handles.set(r.toString("hex"),t),r}getHandle(t){return this.handles.get(t.toString("hex"))}closeHandle(t){this.handles.delete(t.toString("hex"))}attachSftpHandlers(t,e){let r=()=>this.getVfs(),s=()=>this.getUsers();t.on("OPEN",(i,o,a)=>{let c=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(c,e)){On(`[SFTP] Path traversal attempt blocked: user=${e}, path=${c}`),t.status(i,He.PERMISSION_DENIED);return}let l=a,f=!!(l&si.READ),u=!!(l&si.WRITE||l&si.APPEND),h=!!(l&si.CREAT),p=!!(l&si.TRUNC);try{if(!r().exists(c)){if(!h){t.status(i,He.NO_SUCH_FILE);return}r().writeFile(c,Buffer.alloc(0))}if(r().stat(c).type==="directory"){t.status(i,He.FAILURE);return}let y=Buffer.from(r().readFile(c),"utf8");if(p&&(y=Buffer.alloc(0)),l&si.APPEND){let x=this.openHandle({type:"file",path:c,flags:l,buffer:y});t.handle(i,x);return}let b=this.openHandle({type:"file",path:c,flags:l,buffer:y});t.handle(i,b)}catch(A){ns("SFTP OPEN error:",A),t.status(i,He.FAILURE)}}),t.on("READ",(i,o,a,c)=>{let l=this.getHandle(o);if(!l||l.type!=="file"){t.status(i,He.FAILURE);return}if(a>=l.buffer.length){t.status(i,He.EOF);return}let f=l.buffer.slice(a,a+c);t.data(i,f)}),t.on("WRITE",async(i,o,a,c)=>{let l=this.getHandle(o);if(!l||l.type!=="file"){t.status(i,He.FAILURE);return}let f=a+c.length;if(f>l.buffer.length){let u=Buffer.alloc(f);l.buffer.copy(u,0,0,l.buffer.length),l.buffer=u}c.copy(l.buffer,a),t.status(i,He.OK)}),t.on("FSTAT",(i,o)=>{let a=this.getHandle(o);if(!a){t.status(i,He.FAILURE);return}try{let c=r().stat(a.path);t.attrs(i,this.createAttrs(c))}catch{t.status(i,He.FAILURE)}}),t.on("CLOSE",async(i,o)=>{let a=this.getHandle(o);if(!a){t.status(i,He.FAILURE);return}if(a.type==="file")try{s().assertWriteWithinQuota(e,a.path,a.buffer),r().writeFile(a.path,a.buffer)}catch(c){ns("SFTP CLOSE write error:",c),t.status(i,He.FAILURE),this.closeHandle(o);return}this.closeHandle(o),t.status(i,He.OK)}),t.on("OPENDIR",(i,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){On(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(i,He.PERMISSION_DENIED);return}try{if(r().stat(a).type!=="directory"){t.status(i,He.FAILURE);return}let l=r().list(a),f=this.openHandle({type:"dir",path:a,entries:l,index:0});t.handle(i,f)}catch{t.status(i,He.NO_SUCH_FILE)}}),t.on("READDIR",(i,o)=>{let a=this.getHandle(o);if(!a||a.type!=="dir"){t.status(i,He.FAILURE);return}if(a.index>=a.entries.length){t.status(i,He.EOF);return}let c=a.entries[a.index++],l=oi.posix.join(a.path,c),f=r().stat(l),u=this.createAttrs(f),h=`${f.type==="directory"?"d":"-"}${(f.mode&511).toString(8)} ${c}`;return t.name(i,[{filename:c,longname:h,attrs:u}])}),t.on("STAT",(i,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){On(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(i,He.PERMISSION_DENIED);return}try{let c=r().stat(a);t.attrs(i,this.createAttrs(c))}catch{t.status(i,He.NO_SUCH_FILE)}}),t.on("LSTAT",(i,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){On(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(i,He.PERMISSION_DENIED);return}try{let c=r().stat(a);t.attrs(i,this.createAttrs(c))}catch{t.status(i,He.NO_SUCH_FILE)}}),t.on("FSETSTAT",(i,o,a)=>{let c=this.getHandle(o);if(!c){t.status(i,He.FAILURE);return}try{a.mode!==void 0&&r().chmod(c.path,a.mode),t.status(i,He.OK)}catch{t.status(i,He.FAILURE)}}),t.on("SETSTAT",(i,o,a)=>{let c=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(c,e)){On(`[SFTP] Path traversal attempt blocked: user=${e}, path=${c}`),t.status(i,He.PERMISSION_DENIED);return}try{a.mode!==void 0&&r().chmod(c,a.mode),t.status(i,He.OK)}catch{t.status(i,He.FAILURE)}}),t.on("REALPATH",(i,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){On(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(i,He.PERMISSION_DENIED);return}t.name(i,[{filename:a,longname:a,attrs:{mode:16877,uid:0,gid:0,size:0,atime:0,mtime:0}}])}),t.on("MKDIR",(i,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){On(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(i,He.PERMISSION_DENIED);return}try{r().mkdir(a,493),t.status(i,He.OK)}catch{t.status(i,He.FAILURE)}}),t.on("RMDIR",(i,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){On(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(i,He.PERMISSION_DENIED);return}try{r().remove(a,{recursive:!1}),t.status(i,He.OK)}catch{t.status(i,He.FAILURE)}}),t.on("REMOVE",(i,o)=>{let a=this.resolveRequestPath(o,e);if(!this.isPathWithinHome(a,e)){On(`[SFTP] Path traversal attempt blocked: user=${e}, path=${a}`),t.status(i,He.PERMISSION_DENIED);return}try{r().remove(a,{recursive:!1}),t.status(i,He.OK)}catch{t.status(i,He.FAILURE)}}),t.on("RENAME",(i,o,a)=>{let c=this.resolveRequestPath(o,e),l=this.resolveRequestPath(a,e);if(!this.isPathWithinHome(c,e)||!this.isPathWithinHome(l,e)){On(`[SFTP] Path traversal attempt blocked: user=${e}, from=${c}, to=${l}`),t.status(i,He.PERMISSION_DENIED);return}try{r().move(c,l),t.status(i,He.OK)}catch{t.status(i,He.FAILURE)}}),t.on("READLINK",i=>{t.status(i,He.OP_UNSUPPORTED)}),t.on("SYMLINK",i=>{t.status(i,He.OP_UNSUPPORTED)}),t.on("error",i=>{ns(`[SFTP] Stream error for user=${e}:`,i)}),t.on("close",()=>{ii(`[SFTP] Stream closed for user=${e}`),this.handles.clear()}),t.on("end",()=>{ii(`[SFTP] end event for user=${e}`),this.handles.clear()}),t.on("END",()=>{ii(`[SFTP] END event for user=${e}`),this.handles.clear()})}};var Hc=mn("SshMimic"),ZE=!!process.env.DEV_MODE,mp=ZE?console.log.bind(console):()=>{},rs=class extends gp.EventEmitter{port;server;shell;maxAuthAttempts;lockoutDurationMs;authAttempts=new Map;constructor({port:t,hostname:e="typescript-vm",shell:r=new zn(e),maxAuthAttempts:s=5,lockoutDurationMs:i=6e4}){super(),Hc.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}
1300
- `),this.shell.vfs.stopAutoFlush())}async start(){Hc.mark("start");let t=this.shell,e=_o();return await t.ensureInitialized(),this.server=new Ap.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)){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 l=t.users.getAuthorizedKeys(c);if(l.length===0){a.reject();return}let f=a.key;if(!l.some(h=>h.algo===f.algo&&h.data.equals(f.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(),l={cols:80,rows:24};c.on("pty",(f,u,h)=>{l.cols=h?.cols??l.cols,l.rows=h?.rows??l.rows,f()}),c.on("window-change",(f,u,h)=>{l.cols=h?.cols??l.cols,l.rows=h?.rows??l.rows}),c.on("shell",f=>{let u=f();t?.startInteractiveSession(u,s,o,i,l)}),c.on("exec",(f,u,h)=>{let p=f();p&&up(p,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",()=>{mp(`SSH Mimic listening on port ${this.port}`),this.emit("start",{port:this.port}),r(this.port)})})}stop(){Hc.mark("stop"),this.shell.vfs.stopAutoFlush(),this.server&&this.server.close(()=>{mp("SSH Mimic stopped"),this.emit("stop")})}clearLockout(t){this.authAttempts.delete(t)}};var Qc=process.env.SSH_MIMIC_HOSTNAME??"typescript-vm",is=new zn(Qc,void 0,{mode:"fs",snapshotPath:".vfs"});is.addCommand("demo",[],()=>({stdout:"This is a demo command. It does nothing useful.",exitCode:0}));new rs({port:2222,hostname:Qc,shell:is}).start().catch(n=>{console.error("Failed to start SSH Mimic:",n),process.exit(1)});new ai({port:2223,hostname:Qc,shell:is}).start().catch(n=>{console.error("Failed to start SFTP Mimic:",n),process.exit(1)});var Ep=!1;async function yp(n){if(!Ep){Ep=!0,console.log(`
1301
- [${n}] Flushing VFS checkpoint before exit...`);try{await is.vfs.stopAutoFlush(),console.log("[shutdown] Checkpoint written. Goodbye.")}catch(t){console.error("[shutdown] Flush failed:",t)}process.exit(0)}}process.on("SIGINT",()=>{yp("SIGINT")});process.on("SIGTERM",()=>{yp("SIGTERM")});process.on("beforeExit",()=>{is.vfs.stopAutoFlush()});process.on("uncaughtException",n=>{console.debug("Oh my god, something terrible happened: ",n)});process.on("unhandledRejection",(n,t)=>{console.debug(" Oh Lord! We forgot to handle a promise rejection here: ",t),console.debug(" The error was: ",n)});setInterval(()=>{let n=process.memoryUsage().rss;console.debug(`Current memory usage: ${Math.round(n/1024/1024)} MB`)},1e3);