sshclient-wasm 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js DELETED
@@ -1,1934 +0,0 @@
1
- class WebSocketTransport {
2
- constructor(t, n, l) {
3
- this.ws = null, this.callbacks = {}, this.id = t, this.url = n, this.protocols = l;
4
- }
5
- async connect() {
6
- return new Promise((t, n) => {
7
- try {
8
- this.ws = new WebSocket(this.url, this.protocols), this.ws.binaryType = "arraybuffer", this.ws.onopen = () => {
9
- t();
10
- }, this.ws.onerror = (l) => {
11
- const r = new Error("WebSocket error");
12
- this.onError && this.onError(r), n(r);
13
- }, this.ws.onmessage = (l) => {
14
- if (l.data instanceof ArrayBuffer) {
15
- const r = new Uint8Array(l.data);
16
- this.onData && this.onData(r);
17
- }
18
- }, this.ws.onclose = () => {
19
- this.onClose && this.onClose();
20
- };
21
- } catch (l) {
22
- n(l);
23
- }
24
- });
25
- }
26
- async disconnect() {
27
- this.ws && (this.ws.close(), this.ws = null);
28
- }
29
- async send(t) {
30
- if (!this.ws || this.ws.readyState !== WebSocket.OPEN)
31
- throw new Error("WebSocket is not connected");
32
- this.ws.send(t.buffer);
33
- }
34
- setCallbacks(t) {
35
- this.callbacks = t;
36
- }
37
- }
38
- class CustomTransport {
39
- constructor(t, n, l, r) {
40
- this.isConnected = !1, this.id = t, this.connectImpl = n, this.disconnectImpl = l, this.sendImpl = r;
41
- }
42
- async connect() {
43
- this.connectImpl && await this.connectImpl(), this.isConnected = !0;
44
- }
45
- async disconnect() {
46
- this.disconnectImpl && await this.disconnectImpl(), this.isConnected = !1, this.onClose && this.onClose();
47
- }
48
- async send(t) {
49
- if (!this.isConnected)
50
- throw new Error("Transport is not connected");
51
- this.sendImpl && await this.sendImpl(t);
52
- }
53
- // Method to inject received data
54
- injectData(t) {
55
- this.onData && this.onData(t);
56
- }
57
- }
58
- class TransportManager {
59
- constructor() {
60
- this.transports = /* @__PURE__ */ new Map();
61
- }
62
- static getInstance() {
63
- return TransportManager.instance || (TransportManager.instance = new TransportManager()), TransportManager.instance;
64
- }
65
- setWasmInstance(t) {
66
- this.wasmInstance = t;
67
- }
68
- async createTransport(t) {
69
- if (!this.wasmInstance)
70
- throw new Error("WASM instance not set");
71
- console.log("Creating transport with ID:", t.id), console.log("WASM instance available:", !!this.wasmInstance), console.log(
72
- "WASM createTransport function:",
73
- typeof this.wasmInstance.createTransport
74
- );
75
- const n = {
76
- onWrite: (l) => {
77
- t.send(l).catch((r) => {
78
- t.onError && t.onError(r);
79
- });
80
- },
81
- onClose: () => {
82
- t.disconnect().catch(console.error);
83
- }
84
- };
85
- try {
86
- const l = this.wasmInstance.createTransport(t.id, n);
87
- console.log("WASM createTransport result:", l);
88
- } catch (l) {
89
- throw console.error("Error calling WASM createTransport:", l), l;
90
- }
91
- t.onData = (l) => {
92
- this.wasmInstance.injectTransportData(t.id, l);
93
- }, this.transports.set(t.id, t);
94
- }
95
- async closeTransport(t) {
96
- const n = this.transports.get(t);
97
- n && (await n.disconnect(), this.wasmInstance && this.wasmInstance.closeTransport(t), this.transports.delete(t));
98
- }
99
- getTransport(t) {
100
- return this.transports.get(t);
101
- }
102
- }
103
- var commonjsGlobal = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, indexMinimal = {}, minimal$1 = {}, aspromise = asPromise;
104
- function asPromise(o, t) {
105
- for (var n = new Array(arguments.length - 1), l = 0, r = 2, a = !0; r < arguments.length; )
106
- n[l++] = arguments[r++];
107
- return new Promise(function(i, s) {
108
- n[l] = function(u) {
109
- if (a)
110
- if (a = !1, u)
111
- s(u);
112
- else {
113
- for (var f = new Array(arguments.length - 1), d = 0; d < f.length; )
114
- f[d++] = arguments[d];
115
- i.apply(null, f);
116
- }
117
- };
118
- try {
119
- o.apply(t || null, n);
120
- } catch (c) {
121
- a && (a = !1, s(c));
122
- }
123
- });
124
- }
125
- var base64$1 = {};
126
- (function(o) {
127
- var t = o;
128
- t.length = function(i) {
129
- var s = i.length;
130
- if (!s)
131
- return 0;
132
- for (var c = 0; --s % 4 > 1 && i.charAt(s) === "="; )
133
- ++c;
134
- return Math.ceil(i.length * 3) / 4 - c;
135
- };
136
- for (var n = new Array(64), l = new Array(123), r = 0; r < 64; )
137
- l[n[r] = r < 26 ? r + 65 : r < 52 ? r + 71 : r < 62 ? r - 4 : r - 59 | 43] = r++;
138
- t.encode = function(i, s, c) {
139
- for (var u = null, f = [], d = 0, p = 0, h; s < c; ) {
140
- var y = i[s++];
141
- switch (p) {
142
- case 0:
143
- f[d++] = n[y >> 2], h = (y & 3) << 4, p = 1;
144
- break;
145
- case 1:
146
- f[d++] = n[h | y >> 4], h = (y & 15) << 2, p = 2;
147
- break;
148
- case 2:
149
- f[d++] = n[h | y >> 6], f[d++] = n[y & 63], p = 0;
150
- break;
151
- }
152
- d > 8191 && ((u || (u = [])).push(String.fromCharCode.apply(String, f)), d = 0);
153
- }
154
- return p && (f[d++] = n[h], f[d++] = 61, p === 1 && (f[d++] = 61)), u ? (d && u.push(String.fromCharCode.apply(String, f.slice(0, d))), u.join("")) : String.fromCharCode.apply(String, f.slice(0, d));
155
- };
156
- var a = "invalid encoding";
157
- t.decode = function(i, s, c) {
158
- for (var u = c, f = 0, d, p = 0; p < i.length; ) {
159
- var h = i.charCodeAt(p++);
160
- if (h === 61 && f > 1)
161
- break;
162
- if ((h = l[h]) === void 0)
163
- throw Error(a);
164
- switch (f) {
165
- case 0:
166
- d = h, f = 1;
167
- break;
168
- case 1:
169
- s[c++] = d << 2 | (h & 48) >> 4, d = h, f = 2;
170
- break;
171
- case 2:
172
- s[c++] = (d & 15) << 4 | (h & 60) >> 2, d = h, f = 3;
173
- break;
174
- case 3:
175
- s[c++] = (d & 3) << 6 | h, f = 0;
176
- break;
177
- }
178
- }
179
- if (f === 1)
180
- throw Error(a);
181
- return c - u;
182
- }, t.test = function(i) {
183
- return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(i);
184
- };
185
- })(base64$1);
186
- var eventemitter = EventEmitter;
187
- function EventEmitter() {
188
- this._listeners = {};
189
- }
190
- EventEmitter.prototype.on = function(t, n, l) {
191
- return (this._listeners[t] || (this._listeners[t] = [])).push({
192
- fn: n,
193
- ctx: l || this
194
- }), this;
195
- };
196
- EventEmitter.prototype.off = function(t, n) {
197
- if (t === void 0)
198
- this._listeners = {};
199
- else if (n === void 0)
200
- this._listeners[t] = [];
201
- else
202
- for (var l = this._listeners[t], r = 0; r < l.length; )
203
- l[r].fn === n ? l.splice(r, 1) : ++r;
204
- return this;
205
- };
206
- EventEmitter.prototype.emit = function(t) {
207
- var n = this._listeners[t];
208
- if (n) {
209
- for (var l = [], r = 1; r < arguments.length; )
210
- l.push(arguments[r++]);
211
- for (r = 0; r < n.length; )
212
- n[r].fn.apply(n[r++].ctx, l);
213
- }
214
- return this;
215
- };
216
- var float = factory(factory);
217
- function factory(o) {
218
- return typeof Float32Array < "u" ? function() {
219
- var t = new Float32Array([-0]), n = new Uint8Array(t.buffer), l = n[3] === 128;
220
- function r(s, c, u) {
221
- t[0] = s, c[u] = n[0], c[u + 1] = n[1], c[u + 2] = n[2], c[u + 3] = n[3];
222
- }
223
- function a(s, c, u) {
224
- t[0] = s, c[u] = n[3], c[u + 1] = n[2], c[u + 2] = n[1], c[u + 3] = n[0];
225
- }
226
- o.writeFloatLE = l ? r : a, o.writeFloatBE = l ? a : r;
227
- function e(s, c) {
228
- return n[0] = s[c], n[1] = s[c + 1], n[2] = s[c + 2], n[3] = s[c + 3], t[0];
229
- }
230
- function i(s, c) {
231
- return n[3] = s[c], n[2] = s[c + 1], n[1] = s[c + 2], n[0] = s[c + 3], t[0];
232
- }
233
- o.readFloatLE = l ? e : i, o.readFloatBE = l ? i : e;
234
- }() : function() {
235
- function t(l, r, a, e) {
236
- var i = r < 0 ? 1 : 0;
237
- if (i && (r = -r), r === 0)
238
- l(1 / r > 0 ? (
239
- /* positive */
240
- 0
241
- ) : (
242
- /* negative 0 */
243
- 2147483648
244
- ), a, e);
245
- else if (isNaN(r))
246
- l(2143289344, a, e);
247
- else if (r > 34028234663852886e22)
248
- l((i << 31 | 2139095040) >>> 0, a, e);
249
- else if (r < 11754943508222875e-54)
250
- l((i << 31 | Math.round(r / 1401298464324817e-60)) >>> 0, a, e);
251
- else {
252
- var s = Math.floor(Math.log(r) / Math.LN2), c = Math.round(r * Math.pow(2, -s) * 8388608) & 8388607;
253
- l((i << 31 | s + 127 << 23 | c) >>> 0, a, e);
254
- }
255
- }
256
- o.writeFloatLE = t.bind(null, writeUintLE), o.writeFloatBE = t.bind(null, writeUintBE);
257
- function n(l, r, a) {
258
- var e = l(r, a), i = (e >> 31) * 2 + 1, s = e >>> 23 & 255, c = e & 8388607;
259
- return s === 255 ? c ? NaN : i * (1 / 0) : s === 0 ? i * 1401298464324817e-60 * c : i * Math.pow(2, s - 150) * (c + 8388608);
260
- }
261
- o.readFloatLE = n.bind(null, readUintLE), o.readFloatBE = n.bind(null, readUintBE);
262
- }(), typeof Float64Array < "u" ? function() {
263
- var t = new Float64Array([-0]), n = new Uint8Array(t.buffer), l = n[7] === 128;
264
- function r(s, c, u) {
265
- t[0] = s, c[u] = n[0], c[u + 1] = n[1], c[u + 2] = n[2], c[u + 3] = n[3], c[u + 4] = n[4], c[u + 5] = n[5], c[u + 6] = n[6], c[u + 7] = n[7];
266
- }
267
- function a(s, c, u) {
268
- t[0] = s, c[u] = n[7], c[u + 1] = n[6], c[u + 2] = n[5], c[u + 3] = n[4], c[u + 4] = n[3], c[u + 5] = n[2], c[u + 6] = n[1], c[u + 7] = n[0];
269
- }
270
- o.writeDoubleLE = l ? r : a, o.writeDoubleBE = l ? a : r;
271
- function e(s, c) {
272
- return n[0] = s[c], n[1] = s[c + 1], n[2] = s[c + 2], n[3] = s[c + 3], n[4] = s[c + 4], n[5] = s[c + 5], n[6] = s[c + 6], n[7] = s[c + 7], t[0];
273
- }
274
- function i(s, c) {
275
- return n[7] = s[c], n[6] = s[c + 1], n[5] = s[c + 2], n[4] = s[c + 3], n[3] = s[c + 4], n[2] = s[c + 5], n[1] = s[c + 6], n[0] = s[c + 7], t[0];
276
- }
277
- o.readDoubleLE = l ? e : i, o.readDoubleBE = l ? i : e;
278
- }() : function() {
279
- function t(l, r, a, e, i, s) {
280
- var c = e < 0 ? 1 : 0;
281
- if (c && (e = -e), e === 0)
282
- l(0, i, s + r), l(1 / e > 0 ? (
283
- /* positive */
284
- 0
285
- ) : (
286
- /* negative 0 */
287
- 2147483648
288
- ), i, s + a);
289
- else if (isNaN(e))
290
- l(0, i, s + r), l(2146959360, i, s + a);
291
- else if (e > 17976931348623157e292)
292
- l(0, i, s + r), l((c << 31 | 2146435072) >>> 0, i, s + a);
293
- else {
294
- var u;
295
- if (e < 22250738585072014e-324)
296
- u = e / 5e-324, l(u >>> 0, i, s + r), l((c << 31 | u / 4294967296) >>> 0, i, s + a);
297
- else {
298
- var f = Math.floor(Math.log(e) / Math.LN2);
299
- f === 1024 && (f = 1023), u = e * Math.pow(2, -f), l(u * 4503599627370496 >>> 0, i, s + r), l((c << 31 | f + 1023 << 20 | u * 1048576 & 1048575) >>> 0, i, s + a);
300
- }
301
- }
302
- }
303
- o.writeDoubleLE = t.bind(null, writeUintLE, 0, 4), o.writeDoubleBE = t.bind(null, writeUintBE, 4, 0);
304
- function n(l, r, a, e, i) {
305
- var s = l(e, i + r), c = l(e, i + a), u = (c >> 31) * 2 + 1, f = c >>> 20 & 2047, d = 4294967296 * (c & 1048575) + s;
306
- return f === 2047 ? d ? NaN : u * (1 / 0) : f === 0 ? u * 5e-324 * d : u * Math.pow(2, f - 1075) * (d + 4503599627370496);
307
- }
308
- o.readDoubleLE = n.bind(null, readUintLE, 0, 4), o.readDoubleBE = n.bind(null, readUintBE, 4, 0);
309
- }(), o;
310
- }
311
- function writeUintLE(o, t, n) {
312
- t[n] = o & 255, t[n + 1] = o >>> 8 & 255, t[n + 2] = o >>> 16 & 255, t[n + 3] = o >>> 24;
313
- }
314
- function writeUintBE(o, t, n) {
315
- t[n] = o >>> 24, t[n + 1] = o >>> 16 & 255, t[n + 2] = o >>> 8 & 255, t[n + 3] = o & 255;
316
- }
317
- function readUintLE(o, t) {
318
- return (o[t] | o[t + 1] << 8 | o[t + 2] << 16 | o[t + 3] << 24) >>> 0;
319
- }
320
- function readUintBE(o, t) {
321
- return (o[t] << 24 | o[t + 1] << 16 | o[t + 2] << 8 | o[t + 3]) >>> 0;
322
- }
323
- var inquire_1 = inquire;
324
- function inquire(moduleName) {
325
- try {
326
- var mod = eval("quire".replace(/^/, "re"))(moduleName);
327
- if (mod && (mod.length || Object.keys(mod).length))
328
- return mod;
329
- } catch (o) {
330
- }
331
- return null;
332
- }
333
- var utf8$2 = {};
334
- (function(o) {
335
- var t = o;
336
- t.length = function(l) {
337
- for (var r = 0, a = 0, e = 0; e < l.length; ++e)
338
- a = l.charCodeAt(e), a < 128 ? r += 1 : a < 2048 ? r += 2 : (a & 64512) === 55296 && (l.charCodeAt(e + 1) & 64512) === 56320 ? (++e, r += 4) : r += 3;
339
- return r;
340
- }, t.read = function(l, r, a) {
341
- var e = a - r;
342
- if (e < 1)
343
- return "";
344
- for (var i = null, s = [], c = 0, u; r < a; )
345
- u = l[r++], u < 128 ? s[c++] = u : u > 191 && u < 224 ? s[c++] = (u & 31) << 6 | l[r++] & 63 : u > 239 && u < 365 ? (u = ((u & 7) << 18 | (l[r++] & 63) << 12 | (l[r++] & 63) << 6 | l[r++] & 63) - 65536, s[c++] = 55296 + (u >> 10), s[c++] = 56320 + (u & 1023)) : s[c++] = (u & 15) << 12 | (l[r++] & 63) << 6 | l[r++] & 63, c > 8191 && ((i || (i = [])).push(String.fromCharCode.apply(String, s)), c = 0);
346
- return i ? (c && i.push(String.fromCharCode.apply(String, s.slice(0, c))), i.join("")) : String.fromCharCode.apply(String, s.slice(0, c));
347
- }, t.write = function(l, r, a) {
348
- for (var e = a, i, s, c = 0; c < l.length; ++c)
349
- i = l.charCodeAt(c), i < 128 ? r[a++] = i : i < 2048 ? (r[a++] = i >> 6 | 192, r[a++] = i & 63 | 128) : (i & 64512) === 55296 && ((s = l.charCodeAt(c + 1)) & 64512) === 56320 ? (i = 65536 + ((i & 1023) << 10) + (s & 1023), ++c, r[a++] = i >> 18 | 240, r[a++] = i >> 12 & 63 | 128, r[a++] = i >> 6 & 63 | 128, r[a++] = i & 63 | 128) : (r[a++] = i >> 12 | 224, r[a++] = i >> 6 & 63 | 128, r[a++] = i & 63 | 128);
350
- return a - e;
351
- };
352
- })(utf8$2);
353
- var pool_1 = pool;
354
- function pool(o, t, n) {
355
- var l = n || 8192, r = l >>> 1, a = null, e = l;
356
- return function(s) {
357
- if (s < 1 || s > r)
358
- return o(s);
359
- e + s > l && (a = o(l), e = 0);
360
- var c = t.call(a, e, e += s);
361
- return e & 7 && (e = (e | 7) + 1), c;
362
- };
363
- }
364
- var longbits, hasRequiredLongbits;
365
- function requireLongbits() {
366
- if (hasRequiredLongbits) return longbits;
367
- hasRequiredLongbits = 1, longbits = t;
368
- var o = requireMinimal();
369
- function t(a, e) {
370
- this.lo = a >>> 0, this.hi = e >>> 0;
371
- }
372
- var n = t.zero = new t(0, 0);
373
- n.toNumber = function() {
374
- return 0;
375
- }, n.zzEncode = n.zzDecode = function() {
376
- return this;
377
- }, n.length = function() {
378
- return 1;
379
- };
380
- var l = t.zeroHash = "\0\0\0\0\0\0\0\0";
381
- t.fromNumber = function(e) {
382
- if (e === 0)
383
- return n;
384
- var i = e < 0;
385
- i && (e = -e);
386
- var s = e >>> 0, c = (e - s) / 4294967296 >>> 0;
387
- return i && (c = ~c >>> 0, s = ~s >>> 0, ++s > 4294967295 && (s = 0, ++c > 4294967295 && (c = 0))), new t(s, c);
388
- }, t.from = function(e) {
389
- if (typeof e == "number")
390
- return t.fromNumber(e);
391
- if (o.isString(e))
392
- if (o.Long)
393
- e = o.Long.fromString(e);
394
- else
395
- return t.fromNumber(parseInt(e, 10));
396
- return e.low || e.high ? new t(e.low >>> 0, e.high >>> 0) : n;
397
- }, t.prototype.toNumber = function(e) {
398
- if (!e && this.hi >>> 31) {
399
- var i = ~this.lo + 1 >>> 0, s = ~this.hi >>> 0;
400
- return i || (s = s + 1 >>> 0), -(i + s * 4294967296);
401
- }
402
- return this.lo + this.hi * 4294967296;
403
- }, t.prototype.toLong = function(e) {
404
- return o.Long ? new o.Long(this.lo | 0, this.hi | 0, !!e) : { low: this.lo | 0, high: this.hi | 0, unsigned: !!e };
405
- };
406
- var r = String.prototype.charCodeAt;
407
- return t.fromHash = function(e) {
408
- return e === l ? n : new t(
409
- (r.call(e, 0) | r.call(e, 1) << 8 | r.call(e, 2) << 16 | r.call(e, 3) << 24) >>> 0,
410
- (r.call(e, 4) | r.call(e, 5) << 8 | r.call(e, 6) << 16 | r.call(e, 7) << 24) >>> 0
411
- );
412
- }, t.prototype.toHash = function() {
413
- return String.fromCharCode(
414
- this.lo & 255,
415
- this.lo >>> 8 & 255,
416
- this.lo >>> 16 & 255,
417
- this.lo >>> 24,
418
- this.hi & 255,
419
- this.hi >>> 8 & 255,
420
- this.hi >>> 16 & 255,
421
- this.hi >>> 24
422
- );
423
- }, t.prototype.zzEncode = function() {
424
- var e = this.hi >> 31;
425
- return this.hi = ((this.hi << 1 | this.lo >>> 31) ^ e) >>> 0, this.lo = (this.lo << 1 ^ e) >>> 0, this;
426
- }, t.prototype.zzDecode = function() {
427
- var e = -(this.lo & 1);
428
- return this.lo = ((this.lo >>> 1 | this.hi << 31) ^ e) >>> 0, this.hi = (this.hi >>> 1 ^ e) >>> 0, this;
429
- }, t.prototype.length = function() {
430
- var e = this.lo, i = (this.lo >>> 28 | this.hi << 4) >>> 0, s = this.hi >>> 24;
431
- return s === 0 ? i === 0 ? e < 16384 ? e < 128 ? 1 : 2 : e < 2097152 ? 3 : 4 : i < 16384 ? i < 128 ? 5 : 6 : i < 2097152 ? 7 : 8 : s < 128 ? 9 : 10;
432
- }, longbits;
433
- }
434
- var hasRequiredMinimal;
435
- function requireMinimal() {
436
- return hasRequiredMinimal || (hasRequiredMinimal = 1, function(o) {
437
- var t = o;
438
- t.asPromise = aspromise, t.base64 = base64$1, t.EventEmitter = eventemitter, t.float = float, t.inquire = inquire_1, t.utf8 = utf8$2, t.pool = pool_1, t.LongBits = requireLongbits(), t.isNode = !!(typeof commonjsGlobal < "u" && commonjsGlobal && commonjsGlobal.process && commonjsGlobal.process.versions && commonjsGlobal.process.versions.node), t.global = t.isNode && commonjsGlobal || typeof window < "u" && window || typeof self < "u" && self || commonjsGlobal, t.emptyArray = Object.freeze ? Object.freeze([]) : (
439
- /* istanbul ignore next */
440
- []
441
- ), t.emptyObject = Object.freeze ? Object.freeze({}) : (
442
- /* istanbul ignore next */
443
- {}
444
- ), t.isInteger = Number.isInteger || /* istanbul ignore next */
445
- function(a) {
446
- return typeof a == "number" && isFinite(a) && Math.floor(a) === a;
447
- }, t.isString = function(a) {
448
- return typeof a == "string" || a instanceof String;
449
- }, t.isObject = function(a) {
450
- return a && typeof a == "object";
451
- }, t.isset = /**
452
- * Checks if a property on a message is considered to be present.
453
- * @param {Object} obj Plain object or message instance
454
- * @param {string} prop Property name
455
- * @returns {boolean} `true` if considered to be present, otherwise `false`
456
- */
457
- t.isSet = function(a, e) {
458
- var i = a[e];
459
- return i != null && a.hasOwnProperty(e) ? typeof i != "object" || (Array.isArray(i) ? i.length : Object.keys(i).length) > 0 : !1;
460
- }, t.Buffer = function() {
461
- try {
462
- var r = t.inquire("buffer").Buffer;
463
- return r.prototype.utf8Write ? r : (
464
- /* istanbul ignore next */
465
- null
466
- );
467
- } catch {
468
- return null;
469
- }
470
- }(), t._Buffer_from = null, t._Buffer_allocUnsafe = null, t.newBuffer = function(a) {
471
- return typeof a == "number" ? t.Buffer ? t._Buffer_allocUnsafe(a) : new t.Array(a) : t.Buffer ? t._Buffer_from(a) : typeof Uint8Array > "u" ? a : new Uint8Array(a);
472
- }, t.Array = typeof Uint8Array < "u" ? Uint8Array : Array, t.Long = /* istanbul ignore next */
473
- t.global.dcodeIO && /* istanbul ignore next */
474
- t.global.dcodeIO.Long || /* istanbul ignore next */
475
- t.global.Long || t.inquire("long"), t.key2Re = /^true|false|0|1$/, t.key32Re = /^-?(?:0|[1-9][0-9]*)$/, t.key64Re = /^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/, t.longToHash = function(a) {
476
- return a ? t.LongBits.from(a).toHash() : t.LongBits.zeroHash;
477
- }, t.longFromHash = function(a, e) {
478
- var i = t.LongBits.fromHash(a);
479
- return t.Long ? t.Long.fromBits(i.lo, i.hi, e) : i.toNumber(!!e);
480
- };
481
- function n(r, a, e) {
482
- for (var i = Object.keys(a), s = 0; s < i.length; ++s)
483
- (r[i[s]] === void 0 || !e) && (r[i[s]] = a[i[s]]);
484
- return r;
485
- }
486
- t.merge = n, t.lcFirst = function(a) {
487
- return a.charAt(0).toLowerCase() + a.substring(1);
488
- };
489
- function l(r) {
490
- function a(e, i) {
491
- if (!(this instanceof a))
492
- return new a(e, i);
493
- Object.defineProperty(this, "message", { get: function() {
494
- return e;
495
- } }), Error.captureStackTrace ? Error.captureStackTrace(this, a) : Object.defineProperty(this, "stack", { value: new Error().stack || "" }), i && n(this, i);
496
- }
497
- return a.prototype = Object.create(Error.prototype, {
498
- constructor: {
499
- value: a,
500
- writable: !0,
501
- enumerable: !1,
502
- configurable: !0
503
- },
504
- name: {
505
- get: function() {
506
- return r;
507
- },
508
- set: void 0,
509
- enumerable: !1,
510
- // configurable: false would accurately preserve the behavior of
511
- // the original, but I'm guessing that was not intentional.
512
- // For an actual error subclass, this property would
513
- // be configurable.
514
- configurable: !0
515
- },
516
- toString: {
517
- value: function() {
518
- return this.name + ": " + this.message;
519
- },
520
- writable: !0,
521
- enumerable: !1,
522
- configurable: !0
523
- }
524
- }), a;
525
- }
526
- t.newError = l, t.ProtocolError = l("ProtocolError"), t.oneOfGetter = function(a) {
527
- for (var e = {}, i = 0; i < a.length; ++i)
528
- e[a[i]] = 1;
529
- return function() {
530
- for (var s = Object.keys(this), c = s.length - 1; c > -1; --c)
531
- if (e[s[c]] === 1 && this[s[c]] !== void 0 && this[s[c]] !== null)
532
- return s[c];
533
- };
534
- }, t.oneOfSetter = function(a) {
535
- return function(e) {
536
- for (var i = 0; i < a.length; ++i)
537
- a[i] !== e && delete this[a[i]];
538
- };
539
- }, t.toJSONOptions = {
540
- longs: String,
541
- enums: String,
542
- bytes: String,
543
- json: !0
544
- }, t._configure = function() {
545
- var r = t.Buffer;
546
- if (!r) {
547
- t._Buffer_from = t._Buffer_allocUnsafe = null;
548
- return;
549
- }
550
- t._Buffer_from = r.from !== Uint8Array.from && r.from || /* istanbul ignore next */
551
- function(e, i) {
552
- return new r(e, i);
553
- }, t._Buffer_allocUnsafe = r.allocUnsafe || /* istanbul ignore next */
554
- function(e) {
555
- return new r(e);
556
- };
557
- };
558
- }(minimal$1)), minimal$1;
559
- }
560
- var writer = Writer$1, util$4 = requireMinimal(), BufferWriter$1, LongBits$1 = util$4.LongBits, base64 = util$4.base64, utf8$1 = util$4.utf8;
561
- function Op(o, t, n) {
562
- this.fn = o, this.len = t, this.next = void 0, this.val = n;
563
- }
564
- function noop() {
565
- }
566
- function State(o) {
567
- this.head = o.head, this.tail = o.tail, this.len = o.len, this.next = o.states;
568
- }
569
- function Writer$1() {
570
- this.len = 0, this.head = new Op(noop, 0, 0), this.tail = this.head, this.states = null;
571
- }
572
- var create$1 = function o() {
573
- return util$4.Buffer ? function() {
574
- return (Writer$1.create = function() {
575
- return new BufferWriter$1();
576
- })();
577
- } : function() {
578
- return new Writer$1();
579
- };
580
- };
581
- Writer$1.create = create$1();
582
- Writer$1.alloc = function o(t) {
583
- return new util$4.Array(t);
584
- };
585
- util$4.Array !== Array && (Writer$1.alloc = util$4.pool(Writer$1.alloc, util$4.Array.prototype.subarray));
586
- Writer$1.prototype._push = function o(t, n, l) {
587
- return this.tail = this.tail.next = new Op(t, n, l), this.len += n, this;
588
- };
589
- function writeByte(o, t, n) {
590
- t[n] = o & 255;
591
- }
592
- function writeVarint32(o, t, n) {
593
- for (; o > 127; )
594
- t[n++] = o & 127 | 128, o >>>= 7;
595
- t[n] = o;
596
- }
597
- function VarintOp(o, t) {
598
- this.len = o, this.next = void 0, this.val = t;
599
- }
600
- VarintOp.prototype = Object.create(Op.prototype);
601
- VarintOp.prototype.fn = writeVarint32;
602
- Writer$1.prototype.uint32 = function o(t) {
603
- return this.len += (this.tail = this.tail.next = new VarintOp(
604
- (t = t >>> 0) < 128 ? 1 : t < 16384 ? 2 : t < 2097152 ? 3 : t < 268435456 ? 4 : 5,
605
- t
606
- )).len, this;
607
- };
608
- Writer$1.prototype.int32 = function o(t) {
609
- return t < 0 ? this._push(writeVarint64, 10, LongBits$1.fromNumber(t)) : this.uint32(t);
610
- };
611
- Writer$1.prototype.sint32 = function o(t) {
612
- return this.uint32((t << 1 ^ t >> 31) >>> 0);
613
- };
614
- function writeVarint64(o, t, n) {
615
- for (; o.hi; )
616
- t[n++] = o.lo & 127 | 128, o.lo = (o.lo >>> 7 | o.hi << 25) >>> 0, o.hi >>>= 7;
617
- for (; o.lo > 127; )
618
- t[n++] = o.lo & 127 | 128, o.lo = o.lo >>> 7;
619
- t[n++] = o.lo;
620
- }
621
- Writer$1.prototype.uint64 = function o(t) {
622
- var n = LongBits$1.from(t);
623
- return this._push(writeVarint64, n.length(), n);
624
- };
625
- Writer$1.prototype.int64 = Writer$1.prototype.uint64;
626
- Writer$1.prototype.sint64 = function o(t) {
627
- var n = LongBits$1.from(t).zzEncode();
628
- return this._push(writeVarint64, n.length(), n);
629
- };
630
- Writer$1.prototype.bool = function o(t) {
631
- return this._push(writeByte, 1, t ? 1 : 0);
632
- };
633
- function writeFixed32(o, t, n) {
634
- t[n] = o & 255, t[n + 1] = o >>> 8 & 255, t[n + 2] = o >>> 16 & 255, t[n + 3] = o >>> 24;
635
- }
636
- Writer$1.prototype.fixed32 = function o(t) {
637
- return this._push(writeFixed32, 4, t >>> 0);
638
- };
639
- Writer$1.prototype.sfixed32 = Writer$1.prototype.fixed32;
640
- Writer$1.prototype.fixed64 = function o(t) {
641
- var n = LongBits$1.from(t);
642
- return this._push(writeFixed32, 4, n.lo)._push(writeFixed32, 4, n.hi);
643
- };
644
- Writer$1.prototype.sfixed64 = Writer$1.prototype.fixed64;
645
- Writer$1.prototype.float = function o(t) {
646
- return this._push(util$4.float.writeFloatLE, 4, t);
647
- };
648
- Writer$1.prototype.double = function o(t) {
649
- return this._push(util$4.float.writeDoubleLE, 8, t);
650
- };
651
- var writeBytes = util$4.Array.prototype.set ? function o(t, n, l) {
652
- n.set(t, l);
653
- } : function o(t, n, l) {
654
- for (var r = 0; r < t.length; ++r)
655
- n[l + r] = t[r];
656
- };
657
- Writer$1.prototype.bytes = function o(t) {
658
- var n = t.length >>> 0;
659
- if (!n)
660
- return this._push(writeByte, 1, 0);
661
- if (util$4.isString(t)) {
662
- var l = Writer$1.alloc(n = base64.length(t));
663
- base64.decode(t, l, 0), t = l;
664
- }
665
- return this.uint32(n)._push(writeBytes, n, t);
666
- };
667
- Writer$1.prototype.string = function o(t) {
668
- var n = utf8$1.length(t);
669
- return n ? this.uint32(n)._push(utf8$1.write, n, t) : this._push(writeByte, 1, 0);
670
- };
671
- Writer$1.prototype.fork = function o() {
672
- return this.states = new State(this), this.head = this.tail = new Op(noop, 0, 0), this.len = 0, this;
673
- };
674
- Writer$1.prototype.reset = function o() {
675
- return this.states ? (this.head = this.states.head, this.tail = this.states.tail, this.len = this.states.len, this.states = this.states.next) : (this.head = this.tail = new Op(noop, 0, 0), this.len = 0), this;
676
- };
677
- Writer$1.prototype.ldelim = function o() {
678
- var t = this.head, n = this.tail, l = this.len;
679
- return this.reset().uint32(l), l && (this.tail.next = t.next, this.tail = n, this.len += l), this;
680
- };
681
- Writer$1.prototype.finish = function o() {
682
- for (var t = this.head.next, n = this.constructor.alloc(this.len), l = 0; t; )
683
- t.fn(t.val, n, l), l += t.len, t = t.next;
684
- return n;
685
- };
686
- Writer$1._configure = function(o) {
687
- BufferWriter$1 = o, Writer$1.create = create$1(), BufferWriter$1._configure();
688
- };
689
- var writer_buffer = BufferWriter, Writer = writer;
690
- (BufferWriter.prototype = Object.create(Writer.prototype)).constructor = BufferWriter;
691
- var util$3 = requireMinimal();
692
- function BufferWriter() {
693
- Writer.call(this);
694
- }
695
- BufferWriter._configure = function() {
696
- BufferWriter.alloc = util$3._Buffer_allocUnsafe, BufferWriter.writeBytesBuffer = util$3.Buffer && util$3.Buffer.prototype instanceof Uint8Array && util$3.Buffer.prototype.set.name === "set" ? function(t, n, l) {
697
- n.set(t, l);
698
- } : function(t, n, l) {
699
- if (t.copy)
700
- t.copy(n, l, 0, t.length);
701
- else for (var r = 0; r < t.length; )
702
- n[l++] = t[r++];
703
- };
704
- };
705
- BufferWriter.prototype.bytes = function o(t) {
706
- util$3.isString(t) && (t = util$3._Buffer_from(t, "base64"));
707
- var n = t.length >>> 0;
708
- return this.uint32(n), n && this._push(BufferWriter.writeBytesBuffer, n, t), this;
709
- };
710
- function writeStringBuffer(o, t, n) {
711
- o.length < 40 ? util$3.utf8.write(o, t, n) : t.utf8Write ? t.utf8Write(o, n) : t.write(o, n);
712
- }
713
- BufferWriter.prototype.string = function o(t) {
714
- var n = util$3.Buffer.byteLength(t);
715
- return this.uint32(n), n && this._push(writeStringBuffer, n, t), this;
716
- };
717
- BufferWriter._configure();
718
- var reader = Reader$1, util$2 = requireMinimal(), BufferReader$1, LongBits = util$2.LongBits, utf8 = util$2.utf8;
719
- function indexOutOfRange(o, t) {
720
- return RangeError("index out of range: " + o.pos + " + " + (t || 1) + " > " + o.len);
721
- }
722
- function Reader$1(o) {
723
- this.buf = o, this.pos = 0, this.len = o.length;
724
- }
725
- var create_array = typeof Uint8Array < "u" ? function o(t) {
726
- if (t instanceof Uint8Array || Array.isArray(t))
727
- return new Reader$1(t);
728
- throw Error("illegal buffer");
729
- } : function o(t) {
730
- if (Array.isArray(t))
731
- return new Reader$1(t);
732
- throw Error("illegal buffer");
733
- }, create = function o() {
734
- return util$2.Buffer ? function(n) {
735
- return (Reader$1.create = function(r) {
736
- return util$2.Buffer.isBuffer(r) ? new BufferReader$1(r) : create_array(r);
737
- })(n);
738
- } : create_array;
739
- };
740
- Reader$1.create = create();
741
- Reader$1.prototype._slice = util$2.Array.prototype.subarray || /* istanbul ignore next */
742
- util$2.Array.prototype.slice;
743
- Reader$1.prototype.uint32 = /* @__PURE__ */ function o() {
744
- var t = 4294967295;
745
- return function() {
746
- if (t = (this.buf[this.pos] & 127) >>> 0, this.buf[this.pos++] < 128 || (t = (t | (this.buf[this.pos] & 127) << 7) >>> 0, this.buf[this.pos++] < 128) || (t = (t | (this.buf[this.pos] & 127) << 14) >>> 0, this.buf[this.pos++] < 128) || (t = (t | (this.buf[this.pos] & 127) << 21) >>> 0, this.buf[this.pos++] < 128) || (t = (t | (this.buf[this.pos] & 15) << 28) >>> 0, this.buf[this.pos++] < 128)) return t;
747
- if ((this.pos += 5) > this.len)
748
- throw this.pos = this.len, indexOutOfRange(this, 10);
749
- return t;
750
- };
751
- }();
752
- Reader$1.prototype.int32 = function o() {
753
- return this.uint32() | 0;
754
- };
755
- Reader$1.prototype.sint32 = function o() {
756
- var t = this.uint32();
757
- return t >>> 1 ^ -(t & 1) | 0;
758
- };
759
- function readLongVarint() {
760
- var o = new LongBits(0, 0), t = 0;
761
- if (this.len - this.pos > 4) {
762
- for (; t < 4; ++t)
763
- if (o.lo = (o.lo | (this.buf[this.pos] & 127) << t * 7) >>> 0, this.buf[this.pos++] < 128)
764
- return o;
765
- if (o.lo = (o.lo | (this.buf[this.pos] & 127) << 28) >>> 0, o.hi = (o.hi | (this.buf[this.pos] & 127) >> 4) >>> 0, this.buf[this.pos++] < 128)
766
- return o;
767
- t = 0;
768
- } else {
769
- for (; t < 3; ++t) {
770
- if (this.pos >= this.len)
771
- throw indexOutOfRange(this);
772
- if (o.lo = (o.lo | (this.buf[this.pos] & 127) << t * 7) >>> 0, this.buf[this.pos++] < 128)
773
- return o;
774
- }
775
- return o.lo = (o.lo | (this.buf[this.pos++] & 127) << t * 7) >>> 0, o;
776
- }
777
- if (this.len - this.pos > 4) {
778
- for (; t < 5; ++t)
779
- if (o.hi = (o.hi | (this.buf[this.pos] & 127) << t * 7 + 3) >>> 0, this.buf[this.pos++] < 128)
780
- return o;
781
- } else
782
- for (; t < 5; ++t) {
783
- if (this.pos >= this.len)
784
- throw indexOutOfRange(this);
785
- if (o.hi = (o.hi | (this.buf[this.pos] & 127) << t * 7 + 3) >>> 0, this.buf[this.pos++] < 128)
786
- return o;
787
- }
788
- throw Error("invalid varint encoding");
789
- }
790
- Reader$1.prototype.bool = function o() {
791
- return this.uint32() !== 0;
792
- };
793
- function readFixed32_end(o, t) {
794
- return (o[t - 4] | o[t - 3] << 8 | o[t - 2] << 16 | o[t - 1] << 24) >>> 0;
795
- }
796
- Reader$1.prototype.fixed32 = function o() {
797
- if (this.pos + 4 > this.len)
798
- throw indexOutOfRange(this, 4);
799
- return readFixed32_end(this.buf, this.pos += 4);
800
- };
801
- Reader$1.prototype.sfixed32 = function o() {
802
- if (this.pos + 4 > this.len)
803
- throw indexOutOfRange(this, 4);
804
- return readFixed32_end(this.buf, this.pos += 4) | 0;
805
- };
806
- function readFixed64() {
807
- if (this.pos + 8 > this.len)
808
- throw indexOutOfRange(this, 8);
809
- return new LongBits(readFixed32_end(this.buf, this.pos += 4), readFixed32_end(this.buf, this.pos += 4));
810
- }
811
- Reader$1.prototype.float = function o() {
812
- if (this.pos + 4 > this.len)
813
- throw indexOutOfRange(this, 4);
814
- var t = util$2.float.readFloatLE(this.buf, this.pos);
815
- return this.pos += 4, t;
816
- };
817
- Reader$1.prototype.double = function o() {
818
- if (this.pos + 8 > this.len)
819
- throw indexOutOfRange(this, 4);
820
- var t = util$2.float.readDoubleLE(this.buf, this.pos);
821
- return this.pos += 8, t;
822
- };
823
- Reader$1.prototype.bytes = function o() {
824
- var t = this.uint32(), n = this.pos, l = this.pos + t;
825
- if (l > this.len)
826
- throw indexOutOfRange(this, t);
827
- if (this.pos += t, Array.isArray(this.buf))
828
- return this.buf.slice(n, l);
829
- if (n === l) {
830
- var r = util$2.Buffer;
831
- return r ? r.alloc(0) : new this.buf.constructor(0);
832
- }
833
- return this._slice.call(this.buf, n, l);
834
- };
835
- Reader$1.prototype.string = function o() {
836
- var t = this.bytes();
837
- return utf8.read(t, 0, t.length);
838
- };
839
- Reader$1.prototype.skip = function o(t) {
840
- if (typeof t == "number") {
841
- if (this.pos + t > this.len)
842
- throw indexOutOfRange(this, t);
843
- this.pos += t;
844
- } else
845
- do
846
- if (this.pos >= this.len)
847
- throw indexOutOfRange(this);
848
- while (this.buf[this.pos++] & 128);
849
- return this;
850
- };
851
- Reader$1.prototype.skipType = function(o) {
852
- switch (o) {
853
- case 0:
854
- this.skip();
855
- break;
856
- case 1:
857
- this.skip(8);
858
- break;
859
- case 2:
860
- this.skip(this.uint32());
861
- break;
862
- case 3:
863
- for (; (o = this.uint32() & 7) !== 4; )
864
- this.skipType(o);
865
- break;
866
- case 5:
867
- this.skip(4);
868
- break;
869
- default:
870
- throw Error("invalid wire type " + o + " at offset " + this.pos);
871
- }
872
- return this;
873
- };
874
- Reader$1._configure = function(o) {
875
- BufferReader$1 = o, Reader$1.create = create(), BufferReader$1._configure();
876
- var t = util$2.Long ? "toLong" : (
877
- /* istanbul ignore next */
878
- "toNumber"
879
- );
880
- util$2.merge(Reader$1.prototype, {
881
- int64: function() {
882
- return readLongVarint.call(this)[t](!1);
883
- },
884
- uint64: function() {
885
- return readLongVarint.call(this)[t](!0);
886
- },
887
- sint64: function() {
888
- return readLongVarint.call(this).zzDecode()[t](!1);
889
- },
890
- fixed64: function() {
891
- return readFixed64.call(this)[t](!0);
892
- },
893
- sfixed64: function() {
894
- return readFixed64.call(this)[t](!1);
895
- }
896
- });
897
- };
898
- var reader_buffer = BufferReader, Reader = reader;
899
- (BufferReader.prototype = Object.create(Reader.prototype)).constructor = BufferReader;
900
- var util$1 = requireMinimal();
901
- function BufferReader(o) {
902
- Reader.call(this, o);
903
- }
904
- BufferReader._configure = function() {
905
- util$1.Buffer && (BufferReader.prototype._slice = util$1.Buffer.prototype.slice);
906
- };
907
- BufferReader.prototype.string = function o() {
908
- var t = this.uint32();
909
- return this.buf.utf8Slice ? this.buf.utf8Slice(this.pos, this.pos = Math.min(this.pos + t, this.len)) : this.buf.toString("utf-8", this.pos, this.pos = Math.min(this.pos + t, this.len));
910
- };
911
- BufferReader._configure();
912
- var rpc = {}, service = Service, util = requireMinimal();
913
- (Service.prototype = Object.create(util.EventEmitter.prototype)).constructor = Service;
914
- function Service(o, t, n) {
915
- if (typeof o != "function")
916
- throw TypeError("rpcImpl must be a function");
917
- util.EventEmitter.call(this), this.rpcImpl = o, this.requestDelimited = !!t, this.responseDelimited = !!n;
918
- }
919
- Service.prototype.rpcCall = function o(t, n, l, r, a) {
920
- if (!r)
921
- throw TypeError("request must be specified");
922
- var e = this;
923
- if (!a)
924
- return util.asPromise(o, e, t, n, l, r);
925
- if (!e.rpcImpl) {
926
- setTimeout(function() {
927
- a(Error("already ended"));
928
- }, 0);
929
- return;
930
- }
931
- try {
932
- return e.rpcImpl(
933
- t,
934
- n[e.requestDelimited ? "encodeDelimited" : "encode"](r).finish(),
935
- function(s, c) {
936
- if (s)
937
- return e.emit("error", s, t), a(s);
938
- if (c === null) {
939
- e.end(
940
- /* endedByRPC */
941
- !0
942
- );
943
- return;
944
- }
945
- if (!(c instanceof l))
946
- try {
947
- c = l[e.responseDelimited ? "decodeDelimited" : "decode"](c);
948
- } catch (u) {
949
- return e.emit("error", u, t), a(u);
950
- }
951
- return e.emit("data", c, t), a(null, c);
952
- }
953
- );
954
- } catch (i) {
955
- e.emit("error", i, t), setTimeout(function() {
956
- a(i);
957
- }, 0);
958
- return;
959
- }
960
- };
961
- Service.prototype.end = function o(t) {
962
- return this.rpcImpl && (t || this.rpcImpl(null, null, null), this.rpcImpl = null, this.emit("end").off()), this;
963
- };
964
- (function(o) {
965
- var t = o;
966
- t.Service = service;
967
- })(rpc);
968
- var roots = {};
969
- (function(o) {
970
- var t = o;
971
- t.build = "minimal", t.Writer = writer, t.BufferWriter = writer_buffer, t.Reader = reader, t.BufferReader = reader_buffer, t.util = requireMinimal(), t.rpc = rpc, t.roots = roots, t.configure = n;
972
- function n() {
973
- t.util._configure(), t.Writer._configure(t.BufferWriter), t.Reader._configure(t.BufferReader);
974
- }
975
- n();
976
- })(indexMinimal);
977
- var minimal = indexMinimal;
978
- const $Reader = minimal.Reader, $Writer = minimal.Writer, $util = minimal.util, $root = minimal.roots.default || (minimal.roots.default = {}), com = $root.com = (() => {
979
- const o = {};
980
- return o.amazonaws = function() {
981
- const t = {};
982
- return t.iot = function() {
983
- const n = {};
984
- return n.securedtunneling = function() {
985
- const l = {};
986
- return l.ProtocolV1Message = function() {
987
- function r(a) {
988
- if (a)
989
- for (let e = Object.keys(a), i = 0; i < e.length; ++i)
990
- a[e[i]] != null && (this[e[i]] = a[e[i]]);
991
- }
992
- return r.prototype.type = 0, r.prototype.streamId = 0, r.prototype.ignorable = !1, r.prototype.payload = $util.newBuffer([]), r.create = function(e) {
993
- return new r(e);
994
- }, r.encode = function(e, i) {
995
- return i || (i = $Writer.create()), e.type != null && Object.hasOwnProperty.call(e, "type") && i.uint32(
996
- /* id 1, wireType 0 =*/
997
- 8
998
- ).int32(e.type), e.streamId != null && Object.hasOwnProperty.call(e, "streamId") && i.uint32(
999
- /* id 2, wireType 0 =*/
1000
- 16
1001
- ).int32(e.streamId), e.ignorable != null && Object.hasOwnProperty.call(e, "ignorable") && i.uint32(
1002
- /* id 3, wireType 0 =*/
1003
- 24
1004
- ).bool(e.ignorable), e.payload != null && Object.hasOwnProperty.call(e, "payload") && i.uint32(
1005
- /* id 4, wireType 2 =*/
1006
- 34
1007
- ).bytes(e.payload), i;
1008
- }, r.encodeDelimited = function(e, i) {
1009
- return this.encode(e, i).ldelim();
1010
- }, r.decode = function(e, i, s) {
1011
- e instanceof $Reader || (e = $Reader.create(e));
1012
- let c = i === void 0 ? e.len : e.pos + i, u = new $root.com.amazonaws.iot.securedtunneling.ProtocolV1Message();
1013
- for (; e.pos < c; ) {
1014
- let f = e.uint32();
1015
- if (f === s)
1016
- break;
1017
- switch (f >>> 3) {
1018
- case 1: {
1019
- u.type = e.int32();
1020
- break;
1021
- }
1022
- case 2: {
1023
- u.streamId = e.int32();
1024
- break;
1025
- }
1026
- case 3: {
1027
- u.ignorable = e.bool();
1028
- break;
1029
- }
1030
- case 4: {
1031
- u.payload = e.bytes();
1032
- break;
1033
- }
1034
- default:
1035
- e.skipType(f & 7);
1036
- break;
1037
- }
1038
- }
1039
- return u;
1040
- }, r.decodeDelimited = function(e) {
1041
- return e instanceof $Reader || (e = new $Reader(e)), this.decode(e, e.uint32());
1042
- }, r.verify = function(e) {
1043
- if (typeof e != "object" || e === null)
1044
- return "object expected";
1045
- if (e.type != null && e.hasOwnProperty("type"))
1046
- switch (e.type) {
1047
- default:
1048
- return "type: enum value expected";
1049
- case 0:
1050
- case 1:
1051
- case 2:
1052
- case 3:
1053
- break;
1054
- }
1055
- return e.streamId != null && e.hasOwnProperty("streamId") && !$util.isInteger(e.streamId) ? "streamId: integer expected" : e.ignorable != null && e.hasOwnProperty("ignorable") && typeof e.ignorable != "boolean" ? "ignorable: boolean expected" : e.payload != null && e.hasOwnProperty("payload") && !(e.payload && typeof e.payload.length == "number" || $util.isString(e.payload)) ? "payload: buffer expected" : null;
1056
- }, r.fromObject = function(e) {
1057
- if (e instanceof $root.com.amazonaws.iot.securedtunneling.ProtocolV1Message)
1058
- return e;
1059
- let i = new $root.com.amazonaws.iot.securedtunneling.ProtocolV1Message();
1060
- switch (e.type) {
1061
- default:
1062
- if (typeof e.type == "number") {
1063
- i.type = e.type;
1064
- break;
1065
- }
1066
- break;
1067
- case "UNKNOWN":
1068
- case 0:
1069
- i.type = 0;
1070
- break;
1071
- case "DATA":
1072
- case 1:
1073
- i.type = 1;
1074
- break;
1075
- case "STREAM_START":
1076
- case 2:
1077
- i.type = 2;
1078
- break;
1079
- case "STREAM_END":
1080
- case 3:
1081
- i.type = 3;
1082
- break;
1083
- }
1084
- return e.streamId != null && (i.streamId = e.streamId | 0), e.ignorable != null && (i.ignorable = !!e.ignorable), e.payload != null && (typeof e.payload == "string" ? $util.base64.decode(e.payload, i.payload = $util.newBuffer($util.base64.length(e.payload)), 0) : e.payload.length >= 0 && (i.payload = e.payload)), i;
1085
- }, r.toObject = function(e, i) {
1086
- i || (i = {});
1087
- let s = {};
1088
- return i.defaults && (s.type = i.enums === String ? "UNKNOWN" : 0, s.streamId = 0, s.ignorable = !1, i.bytes === String ? s.payload = "" : (s.payload = [], i.bytes !== Array && (s.payload = $util.newBuffer(s.payload)))), e.type != null && e.hasOwnProperty("type") && (s.type = i.enums === String ? $root.com.amazonaws.iot.securedtunneling.ProtocolV1Message.Type[e.type] === void 0 ? e.type : $root.com.amazonaws.iot.securedtunneling.ProtocolV1Message.Type[e.type] : e.type), e.streamId != null && e.hasOwnProperty("streamId") && (s.streamId = e.streamId), e.ignorable != null && e.hasOwnProperty("ignorable") && (s.ignorable = e.ignorable), e.payload != null && e.hasOwnProperty("payload") && (s.payload = i.bytes === String ? $util.base64.encode(e.payload, 0, e.payload.length) : i.bytes === Array ? Array.prototype.slice.call(e.payload) : e.payload), s;
1089
- }, r.prototype.toJSON = function() {
1090
- return this.constructor.toObject(this, minimal.util.toJSONOptions);
1091
- }, r.getTypeUrl = function(e) {
1092
- return e === void 0 && (e = "type.googleapis.com"), e + "/com.amazonaws.iot.securedtunneling.ProtocolV1Message";
1093
- }, r.Type = function() {
1094
- const a = {}, e = Object.create(a);
1095
- return e[a[0] = "UNKNOWN"] = 0, e[a[1] = "DATA"] = 1, e[a[2] = "STREAM_START"] = 2, e[a[3] = "STREAM_END"] = 3, e;
1096
- }(), r;
1097
- }(), l.ProtocolV2Message = function() {
1098
- function r(a) {
1099
- if (this.availableServiceIds = [], a)
1100
- for (let e = Object.keys(a), i = 0; i < e.length; ++i)
1101
- a[e[i]] != null && (this[e[i]] = a[e[i]]);
1102
- }
1103
- return r.prototype.type = 0, r.prototype.streamId = 0, r.prototype.ignorable = !1, r.prototype.payload = $util.newBuffer([]), r.prototype.serviceId = "", r.prototype.availableServiceIds = $util.emptyArray, r.create = function(e) {
1104
- return new r(e);
1105
- }, r.encode = function(e, i) {
1106
- if (i || (i = $Writer.create()), e.type != null && Object.hasOwnProperty.call(e, "type") && i.uint32(
1107
- /* id 1, wireType 0 =*/
1108
- 8
1109
- ).int32(e.type), e.streamId != null && Object.hasOwnProperty.call(e, "streamId") && i.uint32(
1110
- /* id 2, wireType 0 =*/
1111
- 16
1112
- ).int32(e.streamId), e.ignorable != null && Object.hasOwnProperty.call(e, "ignorable") && i.uint32(
1113
- /* id 3, wireType 0 =*/
1114
- 24
1115
- ).bool(e.ignorable), e.payload != null && Object.hasOwnProperty.call(e, "payload") && i.uint32(
1116
- /* id 4, wireType 2 =*/
1117
- 34
1118
- ).bytes(e.payload), e.serviceId != null && Object.hasOwnProperty.call(e, "serviceId") && i.uint32(
1119
- /* id 5, wireType 2 =*/
1120
- 42
1121
- ).string(e.serviceId), e.availableServiceIds != null && e.availableServiceIds.length)
1122
- for (let s = 0; s < e.availableServiceIds.length; ++s)
1123
- i.uint32(
1124
- /* id 6, wireType 2 =*/
1125
- 50
1126
- ).string(e.availableServiceIds[s]);
1127
- return i;
1128
- }, r.encodeDelimited = function(e, i) {
1129
- return this.encode(e, i).ldelim();
1130
- }, r.decode = function(e, i, s) {
1131
- e instanceof $Reader || (e = $Reader.create(e));
1132
- let c = i === void 0 ? e.len : e.pos + i, u = new $root.com.amazonaws.iot.securedtunneling.ProtocolV2Message();
1133
- for (; e.pos < c; ) {
1134
- let f = e.uint32();
1135
- if (f === s)
1136
- break;
1137
- switch (f >>> 3) {
1138
- case 1: {
1139
- u.type = e.int32();
1140
- break;
1141
- }
1142
- case 2: {
1143
- u.streamId = e.int32();
1144
- break;
1145
- }
1146
- case 3: {
1147
- u.ignorable = e.bool();
1148
- break;
1149
- }
1150
- case 4: {
1151
- u.payload = e.bytes();
1152
- break;
1153
- }
1154
- case 5: {
1155
- u.serviceId = e.string();
1156
- break;
1157
- }
1158
- case 6: {
1159
- u.availableServiceIds && u.availableServiceIds.length || (u.availableServiceIds = []), u.availableServiceIds.push(e.string());
1160
- break;
1161
- }
1162
- default:
1163
- e.skipType(f & 7);
1164
- break;
1165
- }
1166
- }
1167
- return u;
1168
- }, r.decodeDelimited = function(e) {
1169
- return e instanceof $Reader || (e = new $Reader(e)), this.decode(e, e.uint32());
1170
- }, r.verify = function(e) {
1171
- if (typeof e != "object" || e === null)
1172
- return "object expected";
1173
- if (e.type != null && e.hasOwnProperty("type"))
1174
- switch (e.type) {
1175
- default:
1176
- return "type: enum value expected";
1177
- case 0:
1178
- case 1:
1179
- case 2:
1180
- case 3:
1181
- case 4:
1182
- case 5:
1183
- break;
1184
- }
1185
- if (e.streamId != null && e.hasOwnProperty("streamId") && !$util.isInteger(e.streamId))
1186
- return "streamId: integer expected";
1187
- if (e.ignorable != null && e.hasOwnProperty("ignorable") && typeof e.ignorable != "boolean")
1188
- return "ignorable: boolean expected";
1189
- if (e.payload != null && e.hasOwnProperty("payload") && !(e.payload && typeof e.payload.length == "number" || $util.isString(e.payload)))
1190
- return "payload: buffer expected";
1191
- if (e.serviceId != null && e.hasOwnProperty("serviceId") && !$util.isString(e.serviceId))
1192
- return "serviceId: string expected";
1193
- if (e.availableServiceIds != null && e.hasOwnProperty("availableServiceIds")) {
1194
- if (!Array.isArray(e.availableServiceIds))
1195
- return "availableServiceIds: array expected";
1196
- for (let i = 0; i < e.availableServiceIds.length; ++i)
1197
- if (!$util.isString(e.availableServiceIds[i]))
1198
- return "availableServiceIds: string[] expected";
1199
- }
1200
- return null;
1201
- }, r.fromObject = function(e) {
1202
- if (e instanceof $root.com.amazonaws.iot.securedtunneling.ProtocolV2Message)
1203
- return e;
1204
- let i = new $root.com.amazonaws.iot.securedtunneling.ProtocolV2Message();
1205
- switch (e.type) {
1206
- default:
1207
- if (typeof e.type == "number") {
1208
- i.type = e.type;
1209
- break;
1210
- }
1211
- break;
1212
- case "UNKNOWN":
1213
- case 0:
1214
- i.type = 0;
1215
- break;
1216
- case "DATA":
1217
- case 1:
1218
- i.type = 1;
1219
- break;
1220
- case "STREAM_START":
1221
- case 2:
1222
- i.type = 2;
1223
- break;
1224
- case "STREAM_RESET":
1225
- case 3:
1226
- i.type = 3;
1227
- break;
1228
- case "SESSION_RESET":
1229
- case 4:
1230
- i.type = 4;
1231
- break;
1232
- case "SERVICE_IDS":
1233
- case 5:
1234
- i.type = 5;
1235
- break;
1236
- }
1237
- if (e.streamId != null && (i.streamId = e.streamId | 0), e.ignorable != null && (i.ignorable = !!e.ignorable), e.payload != null && (typeof e.payload == "string" ? $util.base64.decode(e.payload, i.payload = $util.newBuffer($util.base64.length(e.payload)), 0) : e.payload.length >= 0 && (i.payload = e.payload)), e.serviceId != null && (i.serviceId = String(e.serviceId)), e.availableServiceIds) {
1238
- if (!Array.isArray(e.availableServiceIds))
1239
- throw TypeError(".com.amazonaws.iot.securedtunneling.ProtocolV2Message.availableServiceIds: array expected");
1240
- i.availableServiceIds = [];
1241
- for (let s = 0; s < e.availableServiceIds.length; ++s)
1242
- i.availableServiceIds[s] = String(e.availableServiceIds[s]);
1243
- }
1244
- return i;
1245
- }, r.toObject = function(e, i) {
1246
- i || (i = {});
1247
- let s = {};
1248
- if ((i.arrays || i.defaults) && (s.availableServiceIds = []), i.defaults && (s.type = i.enums === String ? "UNKNOWN" : 0, s.streamId = 0, s.ignorable = !1, i.bytes === String ? s.payload = "" : (s.payload = [], i.bytes !== Array && (s.payload = $util.newBuffer(s.payload))), s.serviceId = ""), e.type != null && e.hasOwnProperty("type") && (s.type = i.enums === String ? $root.com.amazonaws.iot.securedtunneling.ProtocolV2Message.Type[e.type] === void 0 ? e.type : $root.com.amazonaws.iot.securedtunneling.ProtocolV2Message.Type[e.type] : e.type), e.streamId != null && e.hasOwnProperty("streamId") && (s.streamId = e.streamId), e.ignorable != null && e.hasOwnProperty("ignorable") && (s.ignorable = e.ignorable), e.payload != null && e.hasOwnProperty("payload") && (s.payload = i.bytes === String ? $util.base64.encode(e.payload, 0, e.payload.length) : i.bytes === Array ? Array.prototype.slice.call(e.payload) : e.payload), e.serviceId != null && e.hasOwnProperty("serviceId") && (s.serviceId = e.serviceId), e.availableServiceIds && e.availableServiceIds.length) {
1249
- s.availableServiceIds = [];
1250
- for (let c = 0; c < e.availableServiceIds.length; ++c)
1251
- s.availableServiceIds[c] = e.availableServiceIds[c];
1252
- }
1253
- return s;
1254
- }, r.prototype.toJSON = function() {
1255
- return this.constructor.toObject(this, minimal.util.toJSONOptions);
1256
- }, r.getTypeUrl = function(e) {
1257
- return e === void 0 && (e = "type.googleapis.com"), e + "/com.amazonaws.iot.securedtunneling.ProtocolV2Message";
1258
- }, r.Type = function() {
1259
- const a = {}, e = Object.create(a);
1260
- return e[a[0] = "UNKNOWN"] = 0, e[a[1] = "DATA"] = 1, e[a[2] = "STREAM_START"] = 2, e[a[3] = "STREAM_RESET"] = 3, e[a[4] = "SESSION_RESET"] = 4, e[a[5] = "SERVICE_IDS"] = 5, e;
1261
- }(), r;
1262
- }(), l.ProtocolV3Message = function() {
1263
- function r(a) {
1264
- if (this.availableServiceIds = [], a)
1265
- for (let e = Object.keys(a), i = 0; i < e.length; ++i)
1266
- a[e[i]] != null && (this[e[i]] = a[e[i]]);
1267
- }
1268
- return r.prototype.type = 0, r.prototype.streamId = 0, r.prototype.ignorable = !1, r.prototype.payload = $util.newBuffer([]), r.prototype.serviceId = "", r.prototype.availableServiceIds = $util.emptyArray, r.prototype.connectionId = 0, r.create = function(e) {
1269
- return new r(e);
1270
- }, r.encode = function(e, i) {
1271
- if (i || (i = $Writer.create()), e.type != null && Object.hasOwnProperty.call(e, "type") && i.uint32(
1272
- /* id 1, wireType 0 =*/
1273
- 8
1274
- ).int32(e.type), e.streamId != null && Object.hasOwnProperty.call(e, "streamId") && i.uint32(
1275
- /* id 2, wireType 0 =*/
1276
- 16
1277
- ).int32(e.streamId), e.ignorable != null && Object.hasOwnProperty.call(e, "ignorable") && i.uint32(
1278
- /* id 3, wireType 0 =*/
1279
- 24
1280
- ).bool(e.ignorable), e.payload != null && Object.hasOwnProperty.call(e, "payload") && i.uint32(
1281
- /* id 4, wireType 2 =*/
1282
- 34
1283
- ).bytes(e.payload), e.serviceId != null && Object.hasOwnProperty.call(e, "serviceId") && i.uint32(
1284
- /* id 5, wireType 2 =*/
1285
- 42
1286
- ).string(e.serviceId), e.availableServiceIds != null && e.availableServiceIds.length)
1287
- for (let s = 0; s < e.availableServiceIds.length; ++s)
1288
- i.uint32(
1289
- /* id 6, wireType 2 =*/
1290
- 50
1291
- ).string(e.availableServiceIds[s]);
1292
- return e.connectionId != null && Object.hasOwnProperty.call(e, "connectionId") && i.uint32(
1293
- /* id 7, wireType 0 =*/
1294
- 56
1295
- ).uint32(e.connectionId), i;
1296
- }, r.encodeDelimited = function(e, i) {
1297
- return this.encode(e, i).ldelim();
1298
- }, r.decode = function(e, i, s) {
1299
- e instanceof $Reader || (e = $Reader.create(e));
1300
- let c = i === void 0 ? e.len : e.pos + i, u = new $root.com.amazonaws.iot.securedtunneling.ProtocolV3Message();
1301
- for (; e.pos < c; ) {
1302
- let f = e.uint32();
1303
- if (f === s)
1304
- break;
1305
- switch (f >>> 3) {
1306
- case 1: {
1307
- u.type = e.int32();
1308
- break;
1309
- }
1310
- case 2: {
1311
- u.streamId = e.int32();
1312
- break;
1313
- }
1314
- case 3: {
1315
- u.ignorable = e.bool();
1316
- break;
1317
- }
1318
- case 4: {
1319
- u.payload = e.bytes();
1320
- break;
1321
- }
1322
- case 5: {
1323
- u.serviceId = e.string();
1324
- break;
1325
- }
1326
- case 6: {
1327
- u.availableServiceIds && u.availableServiceIds.length || (u.availableServiceIds = []), u.availableServiceIds.push(e.string());
1328
- break;
1329
- }
1330
- case 7: {
1331
- u.connectionId = e.uint32();
1332
- break;
1333
- }
1334
- default:
1335
- e.skipType(f & 7);
1336
- break;
1337
- }
1338
- }
1339
- return u;
1340
- }, r.decodeDelimited = function(e) {
1341
- return e instanceof $Reader || (e = new $Reader(e)), this.decode(e, e.uint32());
1342
- }, r.verify = function(e) {
1343
- if (typeof e != "object" || e === null)
1344
- return "object expected";
1345
- if (e.type != null && e.hasOwnProperty("type"))
1346
- switch (e.type) {
1347
- default:
1348
- return "type: enum value expected";
1349
- case 0:
1350
- case 1:
1351
- case 2:
1352
- case 3:
1353
- case 4:
1354
- case 5:
1355
- case 6:
1356
- case 7:
1357
- break;
1358
- }
1359
- if (e.streamId != null && e.hasOwnProperty("streamId") && !$util.isInteger(e.streamId))
1360
- return "streamId: integer expected";
1361
- if (e.ignorable != null && e.hasOwnProperty("ignorable") && typeof e.ignorable != "boolean")
1362
- return "ignorable: boolean expected";
1363
- if (e.payload != null && e.hasOwnProperty("payload") && !(e.payload && typeof e.payload.length == "number" || $util.isString(e.payload)))
1364
- return "payload: buffer expected";
1365
- if (e.serviceId != null && e.hasOwnProperty("serviceId") && !$util.isString(e.serviceId))
1366
- return "serviceId: string expected";
1367
- if (e.availableServiceIds != null && e.hasOwnProperty("availableServiceIds")) {
1368
- if (!Array.isArray(e.availableServiceIds))
1369
- return "availableServiceIds: array expected";
1370
- for (let i = 0; i < e.availableServiceIds.length; ++i)
1371
- if (!$util.isString(e.availableServiceIds[i]))
1372
- return "availableServiceIds: string[] expected";
1373
- }
1374
- return e.connectionId != null && e.hasOwnProperty("connectionId") && !$util.isInteger(e.connectionId) ? "connectionId: integer expected" : null;
1375
- }, r.fromObject = function(e) {
1376
- if (e instanceof $root.com.amazonaws.iot.securedtunneling.ProtocolV3Message)
1377
- return e;
1378
- let i = new $root.com.amazonaws.iot.securedtunneling.ProtocolV3Message();
1379
- switch (e.type) {
1380
- default:
1381
- if (typeof e.type == "number") {
1382
- i.type = e.type;
1383
- break;
1384
- }
1385
- break;
1386
- case "UNKNOWN":
1387
- case 0:
1388
- i.type = 0;
1389
- break;
1390
- case "DATA":
1391
- case 1:
1392
- i.type = 1;
1393
- break;
1394
- case "STREAM_START":
1395
- case 2:
1396
- i.type = 2;
1397
- break;
1398
- case "STREAM_RESET":
1399
- case 3:
1400
- i.type = 3;
1401
- break;
1402
- case "SESSION_RESET":
1403
- case 4:
1404
- i.type = 4;
1405
- break;
1406
- case "SERVICE_IDS":
1407
- case 5:
1408
- i.type = 5;
1409
- break;
1410
- case "CONNECTION_START":
1411
- case 6:
1412
- i.type = 6;
1413
- break;
1414
- case "CONNECTION_RESET":
1415
- case 7:
1416
- i.type = 7;
1417
- break;
1418
- }
1419
- if (e.streamId != null && (i.streamId = e.streamId | 0), e.ignorable != null && (i.ignorable = !!e.ignorable), e.payload != null && (typeof e.payload == "string" ? $util.base64.decode(e.payload, i.payload = $util.newBuffer($util.base64.length(e.payload)), 0) : e.payload.length >= 0 && (i.payload = e.payload)), e.serviceId != null && (i.serviceId = String(e.serviceId)), e.availableServiceIds) {
1420
- if (!Array.isArray(e.availableServiceIds))
1421
- throw TypeError(".com.amazonaws.iot.securedtunneling.ProtocolV3Message.availableServiceIds: array expected");
1422
- i.availableServiceIds = [];
1423
- for (let s = 0; s < e.availableServiceIds.length; ++s)
1424
- i.availableServiceIds[s] = String(e.availableServiceIds[s]);
1425
- }
1426
- return e.connectionId != null && (i.connectionId = e.connectionId >>> 0), i;
1427
- }, r.toObject = function(e, i) {
1428
- i || (i = {});
1429
- let s = {};
1430
- if ((i.arrays || i.defaults) && (s.availableServiceIds = []), i.defaults && (s.type = i.enums === String ? "UNKNOWN" : 0, s.streamId = 0, s.ignorable = !1, i.bytes === String ? s.payload = "" : (s.payload = [], i.bytes !== Array && (s.payload = $util.newBuffer(s.payload))), s.serviceId = "", s.connectionId = 0), e.type != null && e.hasOwnProperty("type") && (s.type = i.enums === String ? $root.com.amazonaws.iot.securedtunneling.ProtocolV3Message.Type[e.type] === void 0 ? e.type : $root.com.amazonaws.iot.securedtunneling.ProtocolV3Message.Type[e.type] : e.type), e.streamId != null && e.hasOwnProperty("streamId") && (s.streamId = e.streamId), e.ignorable != null && e.hasOwnProperty("ignorable") && (s.ignorable = e.ignorable), e.payload != null && e.hasOwnProperty("payload") && (s.payload = i.bytes === String ? $util.base64.encode(e.payload, 0, e.payload.length) : i.bytes === Array ? Array.prototype.slice.call(e.payload) : e.payload), e.serviceId != null && e.hasOwnProperty("serviceId") && (s.serviceId = e.serviceId), e.availableServiceIds && e.availableServiceIds.length) {
1431
- s.availableServiceIds = [];
1432
- for (let c = 0; c < e.availableServiceIds.length; ++c)
1433
- s.availableServiceIds[c] = e.availableServiceIds[c];
1434
- }
1435
- return e.connectionId != null && e.hasOwnProperty("connectionId") && (s.connectionId = e.connectionId), s;
1436
- }, r.prototype.toJSON = function() {
1437
- return this.constructor.toObject(this, minimal.util.toJSONOptions);
1438
- }, r.getTypeUrl = function(e) {
1439
- return e === void 0 && (e = "type.googleapis.com"), e + "/com.amazonaws.iot.securedtunneling.ProtocolV3Message";
1440
- }, r.Type = function() {
1441
- const a = {}, e = Object.create(a);
1442
- return e[a[0] = "UNKNOWN"] = 0, e[a[1] = "DATA"] = 1, e[a[2] = "STREAM_START"] = 2, e[a[3] = "STREAM_RESET"] = 3, e[a[4] = "SESSION_RESET"] = 4, e[a[5] = "SERVICE_IDS"] = 5, e[a[6] = "CONNECTION_START"] = 6, e[a[7] = "CONNECTION_RESET"] = 7, e;
1443
- }(), r;
1444
- }(), l;
1445
- }(), n;
1446
- }(), t;
1447
- }(), o;
1448
- })(), ProtocolV1Message = com.amazonaws.iot.securedtunneling.ProtocolV1Message, ProtocolV2Message = com.amazonaws.iot.securedtunneling.ProtocolV2Message, ProtocolV3Message = com.amazonaws.iot.securedtunneling.ProtocolV3Message, TunnelMessageType = {
1449
- UNKNOWN: 0,
1450
- DATA: 1,
1451
- STREAM_START: 2,
1452
- STREAM_RESET: 3,
1453
- SESSION_RESET: 4,
1454
- SERVICE_IDS: 5,
1455
- CONNECTION_START: 6,
1456
- CONNECTION_RESET: 7
1457
- };
1458
- class SecureTunnelTransport {
1459
- constructor(t, n) {
1460
- switch (this.ws = null, this.streamId = 1, this.connectionId = 1, this.isConnected = !1, this.tunnelReady = !1, this.messageQueue = [], this.receiveBuffer = new Uint8Array(0), this.id = t, this.config = {
1461
- protocol: "V2",
1462
- ...n
1463
- }, this.config.protocol) {
1464
- case "V1":
1465
- this.messageClass = ProtocolV1Message;
1466
- break;
1467
- case "V2":
1468
- this.messageClass = ProtocolV2Message;
1469
- break;
1470
- case "V3":
1471
- this.messageClass = ProtocolV3Message;
1472
- break;
1473
- default:
1474
- this.messageClass = ProtocolV2Message;
1475
- }
1476
- }
1477
- /**
1478
- * Connect to AWS IoT Secure Tunnel WebSocket endpoint
1479
- */
1480
- async connect() {
1481
- const t = this.buildWebSocketUrl(), r = `aws.iot.securetunneling-${(this.config.protocol || "V2").replace("V", "")}.0`;
1482
- return console.log(`Connecting with WebSocket subprotocol: ${r}`), new Promise((a, e) => {
1483
- try {
1484
- this.ws = new WebSocket(t, r), this.ws.binaryType = "arraybuffer", this.ws.onopen = () => {
1485
- console.log("AWS IoT Secure Tunnel WebSocket connected"), this.isConnected = !0, this.config.clientMode === "destination" ? this.config.serviceId && (console.log(
1486
- "Sending SERVICE_IDS message with serviceId:",
1487
- this.config.serviceId
1488
- ), this.sendControlMessage(TunnelMessageType.SERVICE_IDS, {
1489
- availableServiceIds: [this.config.serviceId]
1490
- })) : (console.log(
1491
- "Source mode: Sending STREAM_START with streamId:",
1492
- this.streamId
1493
- ), this.sendControlMessage(TunnelMessageType.STREAM_START, {
1494
- streamId: this.streamId,
1495
- serviceId: this.config.serviceId
1496
- })), console.log("Waiting for tunnel handshake to complete..."), a();
1497
- }, this.ws.onerror = (i) => {
1498
- const s = new Error(
1499
- "WebSocket error connecting to AWS IoT Secure Tunnel"
1500
- );
1501
- this.onError && this.onError(s), e(s);
1502
- }, this.ws.onmessage = (i) => {
1503
- i.data instanceof ArrayBuffer && this.handleIncomingData(new Uint8Array(i.data));
1504
- }, this.ws.onclose = (i) => {
1505
- console.log("AWS IoT Secure Tunnel WebSocket closed", {
1506
- code: i.code,
1507
- reason: i.reason,
1508
- wasClean: i.wasClean
1509
- }), this.isConnected = !1, this.tunnelReady = !1, this.onClose && this.onClose();
1510
- };
1511
- } catch (i) {
1512
- e(i);
1513
- }
1514
- });
1515
- }
1516
- /**
1517
- * Disconnect from the tunnel
1518
- */
1519
- async disconnect() {
1520
- this.ws && (this.sendControlMessage(TunnelMessageType.STREAM_RESET, {
1521
- streamId: this.streamId
1522
- }), this.ws.close(), this.ws = null), this.isConnected = !1, this.tunnelReady = !1;
1523
- }
1524
- /**
1525
- * Send data through the tunnel
1526
- */
1527
- async send(t) {
1528
- if (!this.isConnected || !this.ws || !this.tunnelReady) {
1529
- console.log(
1530
- "Queueing message, tunnel not ready. Connected:",
1531
- this.isConnected,
1532
- "Ready:",
1533
- this.tunnelReady
1534
- ), this.messageQueue.push(t);
1535
- return;
1536
- }
1537
- this.sendDataFrame(t);
1538
- }
1539
- /**
1540
- * Process queued messages once tunnel is ready
1541
- */
1542
- processQueuedMessages() {
1543
- for (console.log(`Processing ${this.messageQueue.length} queued messages`); this.messageQueue.length > 0; ) {
1544
- const t = this.messageQueue.shift();
1545
- t && this.sendDataFrame(t);
1546
- }
1547
- }
1548
- /**
1549
- * Build the WebSocket URL for AWS IoT Secure Tunneling
1550
- */
1551
- buildWebSocketUrl() {
1552
- const t = `wss://data.tunneling.iot.${this.config.region}.amazonaws.com/tunnel`;
1553
- if (!this.config.accessToken)
1554
- throw console.error("AWS IoT Secure Tunnel: Access token is missing or empty"), new Error(
1555
- "Access token is required for AWS IoT Secure Tunnel connection"
1556
- );
1557
- const n = encodeURIComponent(this.config.accessToken), l = `${t}?local-proxy-mode=${this.config.clientMode}&access-token=${n}`;
1558
- return console.log("AWS IoT Secure Tunnel URL:", l.substring(0, 100) + "..."), console.log("Protocol version:", this.config.protocol || "V2"), l;
1559
- }
1560
- /**
1561
- * Send a control message through the tunnel
1562
- */
1563
- sendControlMessage(t, n = {}) {
1564
- const l = {
1565
- type: t,
1566
- ...n
1567
- };
1568
- console.log("Sending control message:", {
1569
- type: this.getMessageTypeName(t),
1570
- ...n
1571
- });
1572
- const r = this.encodeMessage(l);
1573
- console.log(
1574
- "Encoded message bytes:",
1575
- Array.from(r).map((a) => a.toString(16).padStart(2, "0")).join(" ")
1576
- ), this.sendFrame(r);
1577
- }
1578
- /**
1579
- * Send a data frame through the tunnel
1580
- */
1581
- sendDataFrame(t) {
1582
- for (let l = 0; l < t.length; l += 64512) {
1583
- const r = t.slice(l, Math.min(l + 64512, t.length)), a = {
1584
- type: TunnelMessageType.DATA,
1585
- streamId: this.streamId,
1586
- payload: r
1587
- };
1588
- this.config.serviceId && this.config.protocol !== "V1" && (a.serviceId = this.config.serviceId), this.config.protocol === "V3" && (a.connectionId = this.connectionId), console.log("Sending DATA message with:", {
1589
- type: "DATA",
1590
- streamId: this.streamId,
1591
- serviceId: this.config.serviceId,
1592
- connectionId: this.config.protocol === "V3" ? this.connectionId : void 0,
1593
- payloadSize: r.length
1594
- });
1595
- const e = this.encodeMessage(a);
1596
- this.sendFrame(e);
1597
- }
1598
- }
1599
- /**
1600
- * Send a frame with length prefix
1601
- */
1602
- sendFrame(t) {
1603
- if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
1604
- console.warn("Cannot send frame: WebSocket not open");
1605
- return;
1606
- }
1607
- const n = new Uint8Array(2 + t.length);
1608
- new DataView(n.buffer).setUint16(0, t.length, !1), n.set(t, 2), console.log(
1609
- "Sending frame with length:",
1610
- t.length,
1611
- "Total frame size:",
1612
- n.length
1613
- ), console.log(
1614
- "Frame bytes (first 20):",
1615
- Array.from(n.slice(0, Math.min(20, n.length))).map((r) => r.toString(16).padStart(2, "0")).join(" ")
1616
- ), this.ws.send(n.buffer);
1617
- }
1618
- /**
1619
- * Handle incoming WebSocket data
1620
- */
1621
- handleIncomingData(t) {
1622
- const n = new Uint8Array(this.receiveBuffer.length + t.length);
1623
- for (n.set(this.receiveBuffer), n.set(t, this.receiveBuffer.length), this.receiveBuffer = n; this.receiveBuffer.length >= 2; ) {
1624
- const r = new DataView(
1625
- this.receiveBuffer.buffer,
1626
- this.receiveBuffer.byteOffset
1627
- ).getUint16(0, !1);
1628
- if (this.receiveBuffer.length < 2 + r)
1629
- break;
1630
- const a = this.receiveBuffer.slice(2, 2 + r);
1631
- this.receiveBuffer = this.receiveBuffer.slice(2 + r), console.log(
1632
- "Received frame bytes:",
1633
- Array.from(a).map((e) => e.toString(16).padStart(2, "0")).join(" ")
1634
- );
1635
- try {
1636
- const e = this.decodeMessage(a);
1637
- this.handleMessage(e);
1638
- } catch (e) {
1639
- console.error("Error decoding message:", e), this.onError && this.onError(e);
1640
- }
1641
- }
1642
- }
1643
- /**
1644
- * Handle a decoded tunnel message
1645
- */
1646
- handleMessage(t) {
1647
- var n;
1648
- switch (console.log("Received message:", {
1649
- type: this.getMessageTypeName(t.type),
1650
- streamId: t.streamId,
1651
- connectionId: t.connectionId,
1652
- serviceId: t.serviceId,
1653
- availableServiceIds: t.availableServiceIds,
1654
- payloadSize: (n = t.payload) == null ? void 0 : n.length
1655
- }), t.type) {
1656
- case TunnelMessageType.DATA:
1657
- t.payload && this.onData && this.onData(t.payload);
1658
- break;
1659
- case TunnelMessageType.STREAM_START:
1660
- console.log("Stream started:", t.streamId), this.config.clientMode === "destination" && t.streamId !== void 0 && t.streamId !== null && (this.streamId = t.streamId, console.log("Destination mode: Updated streamId to", this.streamId), this.tunnelReady = !0, this.processQueuedMessages());
1661
- break;
1662
- case TunnelMessageType.STREAM_RESET:
1663
- console.log("Stream reset:", t.streamId), this.onClose && this.onClose();
1664
- break;
1665
- case TunnelMessageType.SESSION_RESET:
1666
- console.log("Session reset"), this.disconnect();
1667
- break;
1668
- case TunnelMessageType.SERVICE_IDS:
1669
- console.log("Available service IDs:", t.availableServiceIds), this.config.clientMode === "source" && (console.log("Source mode: Tunnel ready after receiving SERVICE_IDS"), this.tunnelReady = !0, this.processQueuedMessages());
1670
- break;
1671
- case TunnelMessageType.CONNECTION_START:
1672
- console.log("Connection started:", t.connectionId);
1673
- break;
1674
- case TunnelMessageType.CONNECTION_RESET:
1675
- console.log("Connection reset:", t.connectionId);
1676
- break;
1677
- }
1678
- }
1679
- /**
1680
- * Encode a message using protobufjs
1681
- */
1682
- encodeMessage(t) {
1683
- const n = this.messageClass.create(t);
1684
- return this.messageClass.encode(n).finish();
1685
- }
1686
- /**
1687
- * Decode a message using protobufjs
1688
- */
1689
- decodeMessage(t) {
1690
- return this.messageClass.decode(t);
1691
- }
1692
- /**
1693
- * Get message type name for logging
1694
- */
1695
- getMessageTypeName(t) {
1696
- return {
1697
- 0: "UNKNOWN",
1698
- 1: "DATA",
1699
- 2: "STREAM_START",
1700
- 3: this.config.protocol === "V1" ? "STREAM_END" : "STREAM_RESET",
1701
- 4: "SESSION_RESET",
1702
- 5: "SERVICE_IDS",
1703
- 6: "CONNECTION_START",
1704
- 7: "CONNECTION_RESET"
1705
- }[t] || `UNKNOWN_${t}`;
1706
- }
1707
- }
1708
- function detectFramework() {
1709
- return typeof window > "u" ? "generic" : window.__NEXT_DATA__ || window.next ? "nextjs" : window.__vite_plugin_react_preamble_installed__ ? "vite" : window.__webpack_require__ ? "webpack" : "generic";
1710
- }
1711
- function getAssetPaths(o) {
1712
- const t = detectFramework(), n = o.publicDir || "/";
1713
- if (o.wasmPath && o.wasmExecPath)
1714
- return {
1715
- wasmPath: o.wasmPath,
1716
- wasmExecPath: o.wasmExecPath
1717
- };
1718
- switch (t) {
1719
- case "nextjs":
1720
- return {
1721
- wasmPath: o.wasmPath || `${n}sshclient.wasm`,
1722
- wasmExecPath: o.wasmExecPath || `${n}wasm_exec.js`
1723
- };
1724
- case "vite":
1725
- return {
1726
- wasmPath: o.wasmPath || `${n}sshclient.wasm`,
1727
- wasmExecPath: o.wasmExecPath || `${n}wasm_exec.js`
1728
- };
1729
- default:
1730
- return {
1731
- wasmPath: o.wasmPath || `${n}sshclient.wasm`,
1732
- wasmExecPath: o.wasmExecPath || `${n}wasm_exec.js`
1733
- };
1734
- }
1735
- }
1736
- async function loadWasmExecutor(o, t = 1e4) {
1737
- if (!(typeof window > "u") && !window.Go)
1738
- return new Promise((n, l) => {
1739
- const r = document.createElement("script");
1740
- r.src = o, r.onload = () => n(), r.onerror = () => l(new Error(`Failed to load wasm_exec.js from ${o}`));
1741
- const a = setTimeout(() => {
1742
- l(new Error(`Timeout loading wasm_exec.js from ${o}`));
1743
- }, t);
1744
- r.onload = () => {
1745
- clearTimeout(a), n();
1746
- }, document.head.appendChild(r);
1747
- });
1748
- }
1749
- async function testAssetAvailability(o, t) {
1750
- const n = async (a) => {
1751
- try {
1752
- return (await fetch(a, { method: "HEAD" })).ok;
1753
- } catch {
1754
- return !1;
1755
- }
1756
- }, [l, r] = await Promise.all([
1757
- n(o),
1758
- n(t)
1759
- ]);
1760
- return { wasmAvailable: l, wasmExecAvailable: r };
1761
- }
1762
- const w = class w {
1763
- static async initialize(t = {}) {
1764
- var l;
1765
- if (this.initialized)
1766
- return;
1767
- const n = typeof t == "string" ? { wasmPath: t, autoDetect: !1 } : { autoDetect: !0, cacheBusting: !0, timeout: 1e4, ...t };
1768
- try {
1769
- const { wasmPath: r, wasmExecPath: a } = getAssetPaths(n);
1770
- if (n.autoDetect) {
1771
- const { wasmAvailable: d, wasmExecAvailable: p } = await testAssetAvailability(r, a);
1772
- if (!d)
1773
- throw new Error(`WASM file not found at ${r}. Please ensure sshclient.wasm is in your public directory.`);
1774
- if (!p)
1775
- throw new Error(`wasm_exec.js not found at ${a}. Please ensure wasm_exec.js is in your public directory.`);
1776
- }
1777
- if (await loadWasmExecutor(a, n.timeout), typeof window.Go > "u")
1778
- throw new Error(
1779
- `Go runtime not loaded. Failed to load wasm_exec.js from ${a}.`
1780
- );
1781
- const e = new window.Go();
1782
- let i = r;
1783
- if (n.cacheBusting) {
1784
- const d = `?v=${Date.now()}&t=${(/* @__PURE__ */ new Date()).getTime()}`;
1785
- i += d;
1786
- }
1787
- const s = n.cacheBusting ? {
1788
- cache: "no-cache",
1789
- headers: {
1790
- "Cache-Control": "no-cache",
1791
- Pragma: "no-cache"
1792
- }
1793
- } : {}, c = await fetch(i, s);
1794
- if (!c.ok)
1795
- throw new Error(`Failed to fetch WASM file: ${c.status} ${c.statusText}`);
1796
- const u = await c.arrayBuffer(), f = await WebAssembly.instantiate(u, e.importObject);
1797
- if (e.run(f.instance), await new Promise((d) => setTimeout(d, 100)), this.wasmInstance = window.SSHClient, !this.wasmInstance)
1798
- throw new Error(
1799
- "Failed to initialize WASM module - SSHClient not found on window. The WASM module may not have loaded correctly."
1800
- );
1801
- this.transportManager.setWasmInstance(this.wasmInstance), this.initialized = !0, typeof process < "u" && ((l = process.env) == null ? void 0 : l.NODE_ENV) === "development" && (console.log("SSHClient WASM initialized successfully"), this.wasmInstance.version && console.log(`Version: ${this.wasmInstance.version()}`));
1802
- } catch (r) {
1803
- throw this.initialized = !1, r instanceof Error ? new Error(`SSHClient initialization failed: ${r.message}`) : new Error("SSHClient initialization failed with unknown error");
1804
- }
1805
- }
1806
- static async connect(t, n, l) {
1807
- if (!this.initialized)
1808
- throw new Error("SSHClient not initialized. Call initialize() first.");
1809
- await this.transportManager.createTransport(n), await n.connect();
1810
- const r = l ? {
1811
- onPacketSend: (e, i) => {
1812
- l.onPacketSend && l.onPacketSend(e, i);
1813
- },
1814
- onPacketReceive: (e, i) => {
1815
- l.onPacketReceive && l.onPacketReceive(e, i);
1816
- },
1817
- onStateChange: l.onStateChange
1818
- } : void 0, a = await this.wasmInstance.connect(
1819
- t,
1820
- n.id,
1821
- r
1822
- );
1823
- return {
1824
- sessionId: a.sessionId,
1825
- send: async (e) => {
1826
- await a.send(e);
1827
- },
1828
- disconnect: async () => {
1829
- await a.disconnect(), await this.transportManager.closeTransport(n.id);
1830
- },
1831
- resizeTerminal: async (e, i) => {
1832
- await a.resizeTerminal(e, i);
1833
- }
1834
- };
1835
- }
1836
- static async disconnect(t) {
1837
- if (!this.initialized)
1838
- throw new Error("SSHClient not initialized");
1839
- await this.wasmInstance.disconnect(t);
1840
- }
1841
- static async send(t, n) {
1842
- if (!this.initialized)
1843
- throw new Error("SSHClient not initialized");
1844
- await this.wasmInstance.send(t, n);
1845
- }
1846
- static getVersion() {
1847
- if (!this.initialized)
1848
- throw new Error("SSHClient not initialized");
1849
- return this.wasmInstance.version();
1850
- }
1851
- };
1852
- w.initialized = !1, w.transportManager = TransportManager.getInstance();
1853
- let SSHClient = w;
1854
- class PacketTransformer {
1855
- static toProtobuf(t, n) {
1856
- return t;
1857
- }
1858
- static fromProtobuf(t, n) {
1859
- return t;
1860
- }
1861
- static toBase64(t) {
1862
- return btoa(String.fromCharCode(...t));
1863
- }
1864
- static fromBase64(t) {
1865
- const n = atob(t), l = new Uint8Array(n.length);
1866
- for (let r = 0; r < n.length; r++)
1867
- l[r] = n.charCodeAt(r);
1868
- return l;
1869
- }
1870
- }
1871
- const SSHClientHelpers = {
1872
- /**
1873
- * Get recommended asset paths for the detected framework
1874
- */
1875
- getAssetPaths: (o = "/") => getAssetPaths({ publicDir: o }),
1876
- /**
1877
- * Detect the current framework
1878
- */
1879
- detectFramework,
1880
- /**
1881
- * Test if WASM assets are available at the given paths
1882
- */
1883
- testAssetAvailability,
1884
- /**
1885
- * Next.js specific initialization helper
1886
- */
1887
- initializeForNextJS: async (o = {}) => SSHClient.initialize({
1888
- publicDir: "/",
1889
- autoDetect: !0,
1890
- cacheBusting: process.env.NODE_ENV === "development",
1891
- ...o
1892
- }),
1893
- /**
1894
- * Vite specific initialization helper
1895
- */
1896
- initializeForVite: async (o = {}) => {
1897
- var n, l, r;
1898
- let t = !1;
1899
- try {
1900
- t = ((r = (l = (n = globalThis.import) == null ? void 0 : n.meta) == null ? void 0 : l.env) == null ? void 0 : r.DEV) === !0;
1901
- } catch {
1902
- t = !1;
1903
- }
1904
- return SSHClient.initialize({
1905
- publicDir: "/",
1906
- autoDetect: !0,
1907
- cacheBusting: t,
1908
- ...o
1909
- });
1910
- },
1911
- /**
1912
- * Generic initialization with sensible defaults
1913
- */
1914
- initializeWithDefaults: async (o = {}) => {
1915
- const t = {
1916
- autoDetect: !0,
1917
- cacheBusting: !0,
1918
- timeout: 1e4,
1919
- publicDir: "/"
1920
- };
1921
- return SSHClient.initialize({ ...t, ...o });
1922
- }
1923
- };
1924
- export {
1925
- CustomTransport,
1926
- PacketTransformer,
1927
- SSHClient,
1928
- SSHClientHelpers,
1929
- SecureTunnelTransport,
1930
- TunnelMessageType,
1931
- WebSocketTransport,
1932
- SSHClient as default
1933
- };
1934
- //# sourceMappingURL=index.esm.js.map