stealth-fetch 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of stealth-fetch might be problematic. Click here for more details.
- package/LICENSE +21 -0
- package/README.md +183 -0
- package/dist/client.d.ts +99 -0
- package/dist/client.js +1117 -0
- package/dist/compat/web.d.ts +15 -0
- package/dist/compat/web.js +31 -0
- package/dist/connection-pool.d.ts +39 -0
- package/dist/connection-pool.js +84 -0
- package/dist/dns-cache.d.ts +25 -0
- package/dist/dns-cache.js +44 -0
- package/dist/http1/chunked.d.ts +35 -0
- package/dist/http1/chunked.js +87 -0
- package/dist/http1/client.d.ts +28 -0
- package/dist/http1/client.js +289 -0
- package/dist/http1/parser.d.ts +29 -0
- package/dist/http1/parser.js +78 -0
- package/dist/http2/client.d.ts +64 -0
- package/dist/http2/client.js +97 -0
- package/dist/http2/connection.d.ts +125 -0
- package/dist/http2/connection.js +666 -0
- package/dist/http2/constants.d.ts +72 -0
- package/dist/http2/constants.js +74 -0
- package/dist/http2/flow-control.d.ts +32 -0
- package/dist/http2/flow-control.js +76 -0
- package/dist/http2/framer.d.ts +47 -0
- package/dist/http2/framer.js +133 -0
- package/dist/http2/hpack.d.ts +54 -0
- package/dist/http2/hpack.js +186 -0
- package/dist/http2/parser.d.ts +35 -0
- package/dist/http2/parser.js +72 -0
- package/dist/http2/stream.d.ts +72 -0
- package/dist/http2/stream.js +252 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +33 -0
- package/dist/protocol-cache.d.ts +14 -0
- package/dist/protocol-cache.js +29 -0
- package/dist/socket/adapter.d.ts +59 -0
- package/dist/socket/adapter.js +145 -0
- package/dist/socket/nat64.d.ts +69 -0
- package/dist/socket/nat64.js +196 -0
- package/dist/socket/tls.d.ts +28 -0
- package/dist/socket/tls.js +33 -0
- package/dist/socket/wasm-pkg/wasm_tls.d.ts +107 -0
- package/dist/socket/wasm-pkg/wasm_tls.js +568 -0
- package/dist/socket/wasm-pkg/wasm_tls_bg.wasm +0 -0
- package/dist/socket/wasm-pkg/wasm_tls_bg.wasm.d.ts +20 -0
- package/dist/socket/wasm-tls-adapter.d.ts +40 -0
- package/dist/socket/wasm-tls-adapter.js +102 -0
- package/dist/socket/wasm-tls-bridge.d.ts +30 -0
- package/dist/socket/wasm-tls-bridge.js +187 -0
- package/dist/utils/headers.d.ts +21 -0
- package/dist/utils/headers.js +36 -0
- package/dist/utils/url.d.ts +16 -0
- package/dist/utils/url.js +12 -0
- package/package.json +87 -0
|
@@ -0,0 +1,568 @@
|
|
|
1
|
+
/* @ts-self-types="./wasm_tls.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* TLS connection state, exposed to JS via wasm-bindgen.
|
|
5
|
+
* Uses rustls with buffer-based sync IO — JS layer drives socket IO asynchronously.
|
|
6
|
+
*/
|
|
7
|
+
export class TlsConnection {
|
|
8
|
+
__destroy_into_raw() {
|
|
9
|
+
const ptr = this.__wbg_ptr;
|
|
10
|
+
this.__wbg_ptr = 0;
|
|
11
|
+
TlsConnectionFinalization.unregister(this);
|
|
12
|
+
return ptr;
|
|
13
|
+
}
|
|
14
|
+
free() {
|
|
15
|
+
const ptr = this.__destroy_into_raw();
|
|
16
|
+
wasm.__wbg_tlsconnection_free(ptr, 0);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Feed ciphertext received from the network into the TLS engine.
|
|
20
|
+
* Returns true if rustls has outgoing data to send (call `flush_outgoing_tls`).
|
|
21
|
+
* @param {Uint8Array} data
|
|
22
|
+
* @returns {boolean}
|
|
23
|
+
*/
|
|
24
|
+
feed_ciphertext(data) {
|
|
25
|
+
try {
|
|
26
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
27
|
+
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export2);
|
|
28
|
+
const len0 = WASM_VECTOR_LEN;
|
|
29
|
+
wasm.tlsconnection_feed_ciphertext(retptr, this.__wbg_ptr, ptr0, len0);
|
|
30
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
31
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
32
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
33
|
+
if (r2) {
|
|
34
|
+
throw takeObject(r1);
|
|
35
|
+
}
|
|
36
|
+
return r0 !== 0;
|
|
37
|
+
} finally {
|
|
38
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Flush ciphertext produced by rustls (to be sent over the network).
|
|
43
|
+
* Returns the ciphertext bytes as a Vec<u8> (becomes Uint8Array in JS).
|
|
44
|
+
* @returns {Uint8Array}
|
|
45
|
+
*/
|
|
46
|
+
flush_outgoing_tls() {
|
|
47
|
+
try {
|
|
48
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
49
|
+
wasm.tlsconnection_flush_outgoing_tls(retptr, this.__wbg_ptr);
|
|
50
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
51
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
52
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
53
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
54
|
+
if (r3) {
|
|
55
|
+
throw takeObject(r2);
|
|
56
|
+
}
|
|
57
|
+
var v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
58
|
+
wasm.__wbindgen_export3(r0, r1 * 1, 1);
|
|
59
|
+
return v1;
|
|
60
|
+
} finally {
|
|
61
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Whether the TLS handshake is still in progress.
|
|
66
|
+
* @returns {boolean}
|
|
67
|
+
*/
|
|
68
|
+
is_handshaking() {
|
|
69
|
+
const ret = wasm.tlsconnection_is_handshaking(this.__wbg_ptr);
|
|
70
|
+
return ret !== 0;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get the negotiated ALPN protocol (e.g. "h2" or "http/1.1").
|
|
74
|
+
* Returns null if no ALPN was negotiated.
|
|
75
|
+
* @returns {string | undefined}
|
|
76
|
+
*/
|
|
77
|
+
negotiated_alpn() {
|
|
78
|
+
try {
|
|
79
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
80
|
+
wasm.tlsconnection_negotiated_alpn(retptr, this.__wbg_ptr);
|
|
81
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
82
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
83
|
+
let v1;
|
|
84
|
+
if (r0 !== 0) {
|
|
85
|
+
v1 = getStringFromWasm0(r0, r1).slice();
|
|
86
|
+
wasm.__wbindgen_export3(r0, r1 * 1, 1);
|
|
87
|
+
}
|
|
88
|
+
return v1;
|
|
89
|
+
} finally {
|
|
90
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Create a new TLS client connection.
|
|
95
|
+
* `hostname`: server hostname for SNI
|
|
96
|
+
* `alpn_protocols`: comma-separated ALPN protocol list, e.g. "h2,http/1.1"
|
|
97
|
+
* @param {string} hostname
|
|
98
|
+
* @param {string} alpn_protocols
|
|
99
|
+
*/
|
|
100
|
+
constructor(hostname, alpn_protocols) {
|
|
101
|
+
try {
|
|
102
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
103
|
+
const ptr0 = passStringToWasm0(hostname, wasm.__wbindgen_export2, wasm.__wbindgen_export4);
|
|
104
|
+
const len0 = WASM_VECTOR_LEN;
|
|
105
|
+
const ptr1 = passStringToWasm0(alpn_protocols, wasm.__wbindgen_export2, wasm.__wbindgen_export4);
|
|
106
|
+
const len1 = WASM_VECTOR_LEN;
|
|
107
|
+
wasm.tlsconnection_new(retptr, ptr0, len0, ptr1, len1);
|
|
108
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
109
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
110
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
111
|
+
if (r2) {
|
|
112
|
+
throw takeObject(r1);
|
|
113
|
+
}
|
|
114
|
+
this.__wbg_ptr = r0 >>> 0;
|
|
115
|
+
TlsConnectionFinalization.register(this, this.__wbg_ptr, this);
|
|
116
|
+
return this;
|
|
117
|
+
} finally {
|
|
118
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Send a TLS close_notify alert.
|
|
123
|
+
*/
|
|
124
|
+
send_close_notify() {
|
|
125
|
+
wasm.tlsconnection_send_close_notify(this.__wbg_ptr);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Take decrypted plaintext data (for the upper layer to consume).
|
|
129
|
+
* @returns {Uint8Array}
|
|
130
|
+
*/
|
|
131
|
+
take_plaintext() {
|
|
132
|
+
try {
|
|
133
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
134
|
+
wasm.tlsconnection_take_plaintext(retptr, this.__wbg_ptr);
|
|
135
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
136
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
137
|
+
var v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
138
|
+
wasm.__wbindgen_export3(r0, r1 * 1, 1);
|
|
139
|
+
return v1;
|
|
140
|
+
} finally {
|
|
141
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Whether rustls needs more data from the network.
|
|
146
|
+
* @returns {boolean}
|
|
147
|
+
*/
|
|
148
|
+
wants_read() {
|
|
149
|
+
const ret = wasm.tlsconnection_wants_read(this.__wbg_ptr);
|
|
150
|
+
return ret !== 0;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Whether rustls has data to write to the network.
|
|
154
|
+
* @returns {boolean}
|
|
155
|
+
*/
|
|
156
|
+
wants_write() {
|
|
157
|
+
const ret = wasm.tlsconnection_wants_write(this.__wbg_ptr);
|
|
158
|
+
return ret !== 0;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Write plaintext data (from the upper layer) into the TLS engine for encryption.
|
|
162
|
+
* Returns true if rustls has outgoing data to send.
|
|
163
|
+
* @param {Uint8Array} data
|
|
164
|
+
* @returns {boolean}
|
|
165
|
+
*/
|
|
166
|
+
write_plaintext(data) {
|
|
167
|
+
try {
|
|
168
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
169
|
+
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export2);
|
|
170
|
+
const len0 = WASM_VECTOR_LEN;
|
|
171
|
+
wasm.tlsconnection_write_plaintext(retptr, this.__wbg_ptr, ptr0, len0);
|
|
172
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
173
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
174
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
175
|
+
if (r2) {
|
|
176
|
+
throw takeObject(r1);
|
|
177
|
+
}
|
|
178
|
+
return r0 !== 0;
|
|
179
|
+
} finally {
|
|
180
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (Symbol.dispose) TlsConnection.prototype[Symbol.dispose] = TlsConnection.prototype.free;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Get the library version string (for verification).
|
|
188
|
+
* @returns {string}
|
|
189
|
+
*/
|
|
190
|
+
export function wasm_tls_version() {
|
|
191
|
+
let deferred1_0;
|
|
192
|
+
let deferred1_1;
|
|
193
|
+
try {
|
|
194
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
195
|
+
wasm.wasm_tls_version(retptr);
|
|
196
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
197
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
198
|
+
deferred1_0 = r0;
|
|
199
|
+
deferred1_1 = r1;
|
|
200
|
+
return getStringFromWasm0(r0, r1);
|
|
201
|
+
} finally {
|
|
202
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
203
|
+
wasm.__wbindgen_export3(deferred1_0, deferred1_1, 1);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function __wbg_get_imports() {
|
|
208
|
+
const import0 = {
|
|
209
|
+
__proto__: null,
|
|
210
|
+
__wbg_Error_8c4e43fe74559d73: function(arg0, arg1) {
|
|
211
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
212
|
+
return addHeapObject(ret);
|
|
213
|
+
},
|
|
214
|
+
__wbg___wbindgen_is_function_0095a73b8b156f76: function(arg0) {
|
|
215
|
+
const ret = typeof(getObject(arg0)) === 'function';
|
|
216
|
+
return ret;
|
|
217
|
+
},
|
|
218
|
+
__wbg___wbindgen_is_object_5ae8e5880f2c1fbd: function(arg0) {
|
|
219
|
+
const val = getObject(arg0);
|
|
220
|
+
const ret = typeof(val) === 'object' && val !== null;
|
|
221
|
+
return ret;
|
|
222
|
+
},
|
|
223
|
+
__wbg___wbindgen_is_string_cd444516edc5b180: function(arg0) {
|
|
224
|
+
const ret = typeof(getObject(arg0)) === 'string';
|
|
225
|
+
return ret;
|
|
226
|
+
},
|
|
227
|
+
__wbg___wbindgen_is_undefined_9e4d92534c42d778: function(arg0) {
|
|
228
|
+
const ret = getObject(arg0) === undefined;
|
|
229
|
+
return ret;
|
|
230
|
+
},
|
|
231
|
+
__wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
|
|
232
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
233
|
+
},
|
|
234
|
+
__wbg_call_389efe28435a9388: function() { return handleError(function (arg0, arg1) {
|
|
235
|
+
const ret = getObject(arg0).call(getObject(arg1));
|
|
236
|
+
return addHeapObject(ret);
|
|
237
|
+
}, arguments); },
|
|
238
|
+
__wbg_call_4708e0c13bdc8e95: function() { return handleError(function (arg0, arg1, arg2) {
|
|
239
|
+
const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
|
|
240
|
+
return addHeapObject(ret);
|
|
241
|
+
}, arguments); },
|
|
242
|
+
__wbg_crypto_86f2631e91b51511: function(arg0) {
|
|
243
|
+
const ret = getObject(arg0).crypto;
|
|
244
|
+
return addHeapObject(ret);
|
|
245
|
+
},
|
|
246
|
+
__wbg_getRandomValues_b3f15fcbfabb0f8b: function() { return handleError(function (arg0, arg1) {
|
|
247
|
+
getObject(arg0).getRandomValues(getObject(arg1));
|
|
248
|
+
}, arguments); },
|
|
249
|
+
__wbg_length_32ed9a279acd054c: function(arg0) {
|
|
250
|
+
const ret = getObject(arg0).length;
|
|
251
|
+
return ret;
|
|
252
|
+
},
|
|
253
|
+
__wbg_msCrypto_d562bbe83e0d4b91: function(arg0) {
|
|
254
|
+
const ret = getObject(arg0).msCrypto;
|
|
255
|
+
return addHeapObject(ret);
|
|
256
|
+
},
|
|
257
|
+
__wbg_new_no_args_1c7c842f08d00ebb: function(arg0, arg1) {
|
|
258
|
+
const ret = new Function(getStringFromWasm0(arg0, arg1));
|
|
259
|
+
return addHeapObject(ret);
|
|
260
|
+
},
|
|
261
|
+
__wbg_new_with_length_a2c39cbe88fd8ff1: function(arg0) {
|
|
262
|
+
const ret = new Uint8Array(arg0 >>> 0);
|
|
263
|
+
return addHeapObject(ret);
|
|
264
|
+
},
|
|
265
|
+
__wbg_node_e1f24f89a7336c2e: function(arg0) {
|
|
266
|
+
const ret = getObject(arg0).node;
|
|
267
|
+
return addHeapObject(ret);
|
|
268
|
+
},
|
|
269
|
+
__wbg_now_a3af9a2f4bbaa4d1: function() {
|
|
270
|
+
const ret = Date.now();
|
|
271
|
+
return ret;
|
|
272
|
+
},
|
|
273
|
+
__wbg_process_3975fd6c72f520aa: function(arg0) {
|
|
274
|
+
const ret = getObject(arg0).process;
|
|
275
|
+
return addHeapObject(ret);
|
|
276
|
+
},
|
|
277
|
+
__wbg_prototypesetcall_bdcdcc5842e4d77d: function(arg0, arg1, arg2) {
|
|
278
|
+
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
|
|
279
|
+
},
|
|
280
|
+
__wbg_randomFillSync_f8c153b79f285817: function() { return handleError(function (arg0, arg1) {
|
|
281
|
+
getObject(arg0).randomFillSync(takeObject(arg1));
|
|
282
|
+
}, arguments); },
|
|
283
|
+
__wbg_require_b74f47fc2d022fd6: function() { return handleError(function () {
|
|
284
|
+
const ret = module.require;
|
|
285
|
+
return addHeapObject(ret);
|
|
286
|
+
}, arguments); },
|
|
287
|
+
__wbg_static_accessor_GLOBAL_12837167ad935116: function() {
|
|
288
|
+
const ret = typeof global === 'undefined' ? null : global;
|
|
289
|
+
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
290
|
+
},
|
|
291
|
+
__wbg_static_accessor_GLOBAL_THIS_e628e89ab3b1c95f: function() {
|
|
292
|
+
const ret = typeof globalThis === 'undefined' ? null : globalThis;
|
|
293
|
+
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
294
|
+
},
|
|
295
|
+
__wbg_static_accessor_SELF_a621d3dfbb60d0ce: function() {
|
|
296
|
+
const ret = typeof self === 'undefined' ? null : self;
|
|
297
|
+
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
298
|
+
},
|
|
299
|
+
__wbg_static_accessor_WINDOW_f8727f0cf888e0bd: function() {
|
|
300
|
+
const ret = typeof window === 'undefined' ? null : window;
|
|
301
|
+
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
302
|
+
},
|
|
303
|
+
__wbg_subarray_a96e1fef17ed23cb: function(arg0, arg1, arg2) {
|
|
304
|
+
const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0);
|
|
305
|
+
return addHeapObject(ret);
|
|
306
|
+
},
|
|
307
|
+
__wbg_versions_4e31226f5e8dc909: function(arg0) {
|
|
308
|
+
const ret = getObject(arg0).versions;
|
|
309
|
+
return addHeapObject(ret);
|
|
310
|
+
},
|
|
311
|
+
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
312
|
+
// Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
|
|
313
|
+
const ret = getArrayU8FromWasm0(arg0, arg1);
|
|
314
|
+
return addHeapObject(ret);
|
|
315
|
+
},
|
|
316
|
+
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
317
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
318
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
319
|
+
return addHeapObject(ret);
|
|
320
|
+
},
|
|
321
|
+
__wbindgen_object_clone_ref: function(arg0) {
|
|
322
|
+
const ret = getObject(arg0);
|
|
323
|
+
return addHeapObject(ret);
|
|
324
|
+
},
|
|
325
|
+
__wbindgen_object_drop_ref: function(arg0) {
|
|
326
|
+
takeObject(arg0);
|
|
327
|
+
},
|
|
328
|
+
};
|
|
329
|
+
return {
|
|
330
|
+
__proto__: null,
|
|
331
|
+
"./wasm_tls_bg.js": import0,
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const TlsConnectionFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
336
|
+
? { register: () => {}, unregister: () => {} }
|
|
337
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_tlsconnection_free(ptr >>> 0, 1));
|
|
338
|
+
|
|
339
|
+
function addHeapObject(obj) {
|
|
340
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
341
|
+
const idx = heap_next;
|
|
342
|
+
heap_next = heap[idx];
|
|
343
|
+
|
|
344
|
+
heap[idx] = obj;
|
|
345
|
+
return idx;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function dropObject(idx) {
|
|
349
|
+
if (idx < 132) return;
|
|
350
|
+
heap[idx] = heap_next;
|
|
351
|
+
heap_next = idx;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
355
|
+
ptr = ptr >>> 0;
|
|
356
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
let cachedDataViewMemory0 = null;
|
|
360
|
+
function getDataViewMemory0() {
|
|
361
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
362
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
363
|
+
}
|
|
364
|
+
return cachedDataViewMemory0;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function getStringFromWasm0(ptr, len) {
|
|
368
|
+
ptr = ptr >>> 0;
|
|
369
|
+
return decodeText(ptr, len);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
let cachedUint8ArrayMemory0 = null;
|
|
373
|
+
function getUint8ArrayMemory0() {
|
|
374
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
375
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
376
|
+
}
|
|
377
|
+
return cachedUint8ArrayMemory0;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function getObject(idx) { return heap[idx]; }
|
|
381
|
+
|
|
382
|
+
function handleError(f, args) {
|
|
383
|
+
try {
|
|
384
|
+
return f.apply(this, args);
|
|
385
|
+
} catch (e) {
|
|
386
|
+
wasm.__wbindgen_export(addHeapObject(e));
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
let heap = new Array(128).fill(undefined);
|
|
391
|
+
heap.push(undefined, null, true, false);
|
|
392
|
+
|
|
393
|
+
let heap_next = heap.length;
|
|
394
|
+
|
|
395
|
+
function isLikeNone(x) {
|
|
396
|
+
return x === undefined || x === null;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
400
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
401
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
402
|
+
WASM_VECTOR_LEN = arg.length;
|
|
403
|
+
return ptr;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
407
|
+
if (realloc === undefined) {
|
|
408
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
409
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
410
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
411
|
+
WASM_VECTOR_LEN = buf.length;
|
|
412
|
+
return ptr;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
let len = arg.length;
|
|
416
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
417
|
+
|
|
418
|
+
const mem = getUint8ArrayMemory0();
|
|
419
|
+
|
|
420
|
+
let offset = 0;
|
|
421
|
+
|
|
422
|
+
for (; offset < len; offset++) {
|
|
423
|
+
const code = arg.charCodeAt(offset);
|
|
424
|
+
if (code > 0x7F) break;
|
|
425
|
+
mem[ptr + offset] = code;
|
|
426
|
+
}
|
|
427
|
+
if (offset !== len) {
|
|
428
|
+
if (offset !== 0) {
|
|
429
|
+
arg = arg.slice(offset);
|
|
430
|
+
}
|
|
431
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
432
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
433
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
434
|
+
|
|
435
|
+
offset += ret.written;
|
|
436
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
WASM_VECTOR_LEN = offset;
|
|
440
|
+
return ptr;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
function takeObject(idx) {
|
|
444
|
+
const ret = getObject(idx);
|
|
445
|
+
dropObject(idx);
|
|
446
|
+
return ret;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
450
|
+
cachedTextDecoder.decode();
|
|
451
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
452
|
+
let numBytesDecoded = 0;
|
|
453
|
+
function decodeText(ptr, len) {
|
|
454
|
+
numBytesDecoded += len;
|
|
455
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
456
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
457
|
+
cachedTextDecoder.decode();
|
|
458
|
+
numBytesDecoded = len;
|
|
459
|
+
}
|
|
460
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
const cachedTextEncoder = new TextEncoder();
|
|
464
|
+
|
|
465
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
466
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
467
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
468
|
+
view.set(buf);
|
|
469
|
+
return {
|
|
470
|
+
read: arg.length,
|
|
471
|
+
written: buf.length
|
|
472
|
+
};
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
let WASM_VECTOR_LEN = 0;
|
|
477
|
+
|
|
478
|
+
let wasmModule, wasm;
|
|
479
|
+
function __wbg_finalize_init(instance, module) {
|
|
480
|
+
wasm = instance.exports;
|
|
481
|
+
wasmModule = module;
|
|
482
|
+
cachedDataViewMemory0 = null;
|
|
483
|
+
cachedUint8ArrayMemory0 = null;
|
|
484
|
+
return wasm;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
async function __wbg_load(module, imports) {
|
|
488
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
489
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
490
|
+
try {
|
|
491
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
492
|
+
} catch (e) {
|
|
493
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
494
|
+
|
|
495
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
496
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
497
|
+
|
|
498
|
+
} else { throw e; }
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
const bytes = await module.arrayBuffer();
|
|
503
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
504
|
+
} else {
|
|
505
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
506
|
+
|
|
507
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
508
|
+
return { instance, module };
|
|
509
|
+
} else {
|
|
510
|
+
return instance;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
function expectedResponseType(type) {
|
|
515
|
+
switch (type) {
|
|
516
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
517
|
+
}
|
|
518
|
+
return false;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
function initSync(module) {
|
|
523
|
+
if (wasm !== undefined) return wasm;
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
if (module !== undefined) {
|
|
527
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
528
|
+
({module} = module)
|
|
529
|
+
} else {
|
|
530
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
const imports = __wbg_get_imports();
|
|
535
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
536
|
+
module = new WebAssembly.Module(module);
|
|
537
|
+
}
|
|
538
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
539
|
+
return __wbg_finalize_init(instance, module);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
async function __wbg_init(module_or_path) {
|
|
543
|
+
if (wasm !== undefined) return wasm;
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
if (module_or_path !== undefined) {
|
|
547
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
548
|
+
({module_or_path} = module_or_path)
|
|
549
|
+
} else {
|
|
550
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
if (module_or_path === undefined) {
|
|
555
|
+
module_or_path = new URL('wasm_tls_bg.wasm', import.meta.url);
|
|
556
|
+
}
|
|
557
|
+
const imports = __wbg_get_imports();
|
|
558
|
+
|
|
559
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
560
|
+
module_or_path = fetch(module_or_path);
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
564
|
+
|
|
565
|
+
return __wbg_finalize_init(instance, module);
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
export { initSync, __wbg_init as default };
|
|
Binary file
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const __wbg_tlsconnection_free: (a: number, b: number) => void;
|
|
5
|
+
export const tlsconnection_feed_ciphertext: (a: number, b: number, c: number, d: number) => void;
|
|
6
|
+
export const tlsconnection_flush_outgoing_tls: (a: number, b: number) => void;
|
|
7
|
+
export const tlsconnection_is_handshaking: (a: number) => number;
|
|
8
|
+
export const tlsconnection_negotiated_alpn: (a: number, b: number) => void;
|
|
9
|
+
export const tlsconnection_new: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
10
|
+
export const tlsconnection_send_close_notify: (a: number) => void;
|
|
11
|
+
export const tlsconnection_take_plaintext: (a: number, b: number) => void;
|
|
12
|
+
export const tlsconnection_wants_read: (a: number) => number;
|
|
13
|
+
export const tlsconnection_wants_write: (a: number) => number;
|
|
14
|
+
export const tlsconnection_write_plaintext: (a: number, b: number, c: number, d: number) => void;
|
|
15
|
+
export const wasm_tls_version: (a: number) => void;
|
|
16
|
+
export const __wbindgen_export: (a: number) => void;
|
|
17
|
+
export const __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
18
|
+
export const __wbindgen_export2: (a: number, b: number) => number;
|
|
19
|
+
export const __wbindgen_export3: (a: number, b: number, c: number) => void;
|
|
20
|
+
export const __wbindgen_export4: (a: number, b: number, c: number, d: number) => number;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Duplex } from 'node:stream';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* WasmTlsSocketAdapter: wraps a WASM TLS session as a Node.js Duplex stream.
|
|
5
|
+
* Interface-compatible with CloudflareSocketAdapter — upper-layer code
|
|
6
|
+
* (Http2Connection, http1Request) works without modification.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
interface WasmTlsSocketOptions {
|
|
10
|
+
hostname: string;
|
|
11
|
+
port: number;
|
|
12
|
+
alpnProtocols?: string[];
|
|
13
|
+
/** Override TCP connection hostname (e.g. NAT64 IPv6), while TLS SNI uses `hostname` */
|
|
14
|
+
connectHostname?: string;
|
|
15
|
+
}
|
|
16
|
+
declare class WasmTlsSocketAdapter extends Duplex {
|
|
17
|
+
private rawSocket;
|
|
18
|
+
private tlsSession;
|
|
19
|
+
private _connected;
|
|
20
|
+
readonly hostname: string;
|
|
21
|
+
readonly port: number;
|
|
22
|
+
readonly alpnProtocols: string[];
|
|
23
|
+
/** TCP-level hostname (may differ from TLS SNI hostname for NAT64) */
|
|
24
|
+
readonly connectHostname: string;
|
|
25
|
+
constructor(options: WasmTlsSocketOptions);
|
|
26
|
+
/**
|
|
27
|
+
* Establish connection: raw TCP -> WASM TLS handshake -> ready.
|
|
28
|
+
* @param signal Optional AbortSignal to cancel the handshake (prevents resource leaks on timeout)
|
|
29
|
+
*/
|
|
30
|
+
connect(signal?: AbortSignal): Promise<void>;
|
|
31
|
+
/** Get the negotiated ALPN protocol */
|
|
32
|
+
get negotiatedAlpn(): string | null;
|
|
33
|
+
_read(): void;
|
|
34
|
+
_write(chunk: Buffer | Uint8Array, _encoding: string, callback: (error?: Error | null) => void): void;
|
|
35
|
+
_final(callback: (error?: Error | null) => void): void;
|
|
36
|
+
_destroy(error: Error | null, callback: (error?: Error | null) => void): void;
|
|
37
|
+
get isConnected(): boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { WasmTlsSocketAdapter, type WasmTlsSocketOptions };
|