@volter/tabnode 0.4.1 → 0.5.0
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/__sw__.js +259 -5
- package/dist/assets/{runtime-worker-LWfW6VWE.js → runtime-worker-B9buriZs.js} +4004 -2955
- package/dist/fetch-transport.d.ts +20 -0
- package/dist/guest-timers.d.ts +15 -0
- package/dist/http-client-transport.d.ts +19 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.mjs +5187 -3051
- package/dist/native-stream-binding.d.ts +57 -0
- package/dist/native-stream-owner.d.ts +121 -0
- package/dist/node-lib/binding/duplex_stream.d.ts +26 -0
- package/dist/node-lib/binding/fds.d.ts +8 -0
- package/dist/node-lib/binding/fs.d.ts +311 -78
- package/dist/node-lib/binding/misc.d.ts +1 -0
- package/dist/node-lib/binding/pipe_wrap.d.ts +4 -4
- package/dist/node-lib/binding/process_wrap.d.ts +12 -1
- package/dist/node-lib/binding/stream_wrap.d.ts +27 -18
- package/dist/node-lib/binding/tcp_wrap.d.ts +0 -1
- package/dist/node-lib/binding/tty_wrap.d.ts +43 -2
- package/dist/node-lib/binding/util.d.ts +83 -0
- package/dist/node-lib/binding/uv.d.ts +4 -0
- package/dist/node-lib/fs-module.d.ts +1 -0
- package/dist/node-lib/internals/buffer-and-streams.d.ts +30 -17
- package/dist/node-lib/internals/index.d.ts +1 -1
- package/dist/node-lib/load.d.ts +17 -3
- package/dist/node-lib/module-hooks.d.ts +1 -0
- package/dist/node-lib/public-modules.d.ts +1 -1
- package/dist/node-lib/timers.d.ts +38 -0
- package/dist/node-process-host.d.ts +41 -0
- package/dist/process-registry.d.ts +39 -0
- package/dist/process-tokens.d.ts +11 -0
- package/dist/promise-ownership.d.ts +3 -0
- package/dist/runtime.d.ts +10 -9
- package/dist/shims/child_process.d.ts +2 -0
- package/dist/shims/crypto.d.ts +660 -119
- package/dist/shims/dns.d.ts +76 -2
- package/dist/shims/process.d.ts +1 -0
- package/dist/shims/string_decoder.d.ts +19 -3
- package/dist/shims/tls.d.ts +853 -31
- package/dist/source-edits.d.ts +7 -0
- package/package.json +1 -1
- package/src/code-transforms.ts +2 -3
- package/src/fetch-transport.ts +98 -0
- package/src/guest-timers.ts +89 -0
- package/src/http-client-transport.ts +169 -0
- package/src/index.ts +12 -0
- package/src/native-stream-binding.ts +393 -0
- package/src/native-stream-owner.ts +317 -0
- package/src/node-lib/binding/duplex_stream.ts +95 -0
- package/src/node-lib/binding/fds.ts +18 -1
- package/src/node-lib/binding/fs.ts +45 -17
- package/src/node-lib/binding/misc.ts +2 -0
- package/src/node-lib/binding/pipe_wrap.ts +35 -12
- package/src/node-lib/binding/process_wrap.ts +50 -9
- package/src/node-lib/binding/stream_wrap.ts +196 -72
- package/src/node-lib/binding/tcp_wrap.ts +43 -8
- package/src/node-lib/binding/tty_wrap.ts +135 -8
- package/src/node-lib/binding/util.ts +24 -15
- package/src/node-lib/binding/uv.ts +4 -0
- package/src/node-lib/fs-module.ts +2 -18
- package/src/node-lib/internal/navigator.js +149 -0
- package/src/node-lib/internals/buffer-and-streams.ts +50 -11
- package/src/node-lib/internals/events-util.ts +5 -0
- package/src/node-lib/internals/index.ts +12 -2
- package/src/node-lib/load.ts +170 -62
- package/src/node-lib/module-hooks.ts +5 -2
- package/src/node-lib/public-modules.ts +12 -48
- package/src/node-lib/sources.ts +4 -0
- package/src/node-lib/timers.ts +93 -0
- package/src/node-process-host.ts +124 -0
- package/src/process-registry.ts +144 -0
- package/src/process-tokens.ts +55 -6
- package/src/promise-ownership.ts +28 -0
- package/src/runtime.ts +90 -214
- package/src/shims/child_process.ts +310 -80
- package/src/shims/crypto.ts +115 -100
- package/src/shims/dns.ts +17 -1
- package/src/shims/process.ts +33 -11
- package/src/shims/string_decoder.ts +10 -6
- package/src/shims/tls.ts +49 -19
- package/src/source-edits.ts +20 -0
package/src/shims/crypto.ts
CHANGED
|
@@ -11,10 +11,9 @@ import { md5 } from '@noble/hashes/legacy.js';
|
|
|
11
11
|
// The `buffer` package, not the guest polyfill: the byte-level encodings
|
|
12
12
|
// (utf16le, latin1, offset views) crypto inputs arrive in are its own.
|
|
13
13
|
import { Buffer as HostBuffer } from 'buffer/index.js';
|
|
14
|
-
import { Buffer } from '../node-lib/buffer-module';
|
|
15
|
-
|
|
16
|
-
import {
|
|
17
|
-
import { EventEmitter } from '../node-lib/events-module';
|
|
14
|
+
import type { Buffer, BufferConstructor, BufferModule } from '../node-lib/buffer-module';
|
|
15
|
+
import type { EventsModule } from '../node-lib/events-module';
|
|
16
|
+
import { lazyModule, lazyExport } from '../node-lib/lazy';
|
|
18
17
|
import {
|
|
19
18
|
ERR_INVALID_ARG_TYPE,
|
|
20
19
|
ERR_OUT_OF_RANGE,
|
|
@@ -24,6 +23,21 @@ import {
|
|
|
24
23
|
import { cryptoConstants as constants } from './crypto-constants';
|
|
25
24
|
export { constants };
|
|
26
25
|
|
|
26
|
+
interface DigestState {
|
|
27
|
+
update(data: Uint8Array): DigestState;
|
|
28
|
+
digest(): Uint8Array;
|
|
29
|
+
clone?(): DigestState;
|
|
30
|
+
[field: string]: unknown;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Native crypto allocates guest results and classes in the caller's graph. */
|
|
34
|
+
export function createCryptoModule(require?: (name: string) => any) {
|
|
35
|
+
// The host factory runs inside the builtin loader's import cycle. Create
|
|
36
|
+
// lazy references here; even reading another module's lazy-export constant
|
|
37
|
+
// eagerly can hit its TDZ under a different bundle evaluation order.
|
|
38
|
+
const bufferModule: BufferModule = require ? require('buffer') : lazyModule<BufferModule>('buffer');
|
|
39
|
+
const Buffer: BufferConstructor = require ? bufferModule.Buffer : lazyExport<BufferConstructor>('buffer', 'Buffer');
|
|
40
|
+
const EventEmitter: EventsModule['EventEmitter'] = require ? require('events').EventEmitter : lazyExport<EventsModule['EventEmitter']>('events', 'EventEmitter');
|
|
27
41
|
// ============================================================================
|
|
28
42
|
// Random functions
|
|
29
43
|
// ============================================================================
|
|
@@ -92,14 +106,14 @@ function __assertSize(size: unknown, elementSize: number, offset: number, length
|
|
|
92
106
|
return bytes >>> 0;
|
|
93
107
|
}
|
|
94
108
|
|
|
95
|
-
|
|
96
|
-
|
|
109
|
+
function randomBytes(size: number): Buffer;
|
|
110
|
+
function randomBytes(size: number, callback: (error: Error | null, buffer: Buffer) => void): void;
|
|
97
111
|
/**
|
|
98
112
|
* Node: with a callback, `randomBytes` answers through it and returns nothing;
|
|
99
113
|
* without one it returns the buffer. The engine always returned the buffer and
|
|
100
114
|
* dropped the callback, so a program that only waits on the callback hung.
|
|
101
115
|
*/
|
|
102
|
-
|
|
116
|
+
function randomBytes(
|
|
103
117
|
size: number,
|
|
104
118
|
callback?: (error: Error | null, buffer: Buffer) => void
|
|
105
119
|
): Buffer | void {
|
|
@@ -117,7 +131,7 @@ export function randomBytes(
|
|
|
117
131
|
});
|
|
118
132
|
}
|
|
119
133
|
|
|
120
|
-
|
|
134
|
+
function randomFillSync<T extends ArrayBufferView | ArrayBufferLike>(
|
|
121
135
|
buffer: T,
|
|
122
136
|
offset?: number,
|
|
123
137
|
size?: number
|
|
@@ -137,22 +151,22 @@ export function randomFillSync<T extends ArrayBufferView | ArrayBufferLike>(
|
|
|
137
151
|
* `(buf, offset, cb)`, `(buf, offset, size, cb)`, with the same argument
|
|
138
152
|
* checks `randomFillSync` makes.
|
|
139
153
|
*/
|
|
140
|
-
|
|
154
|
+
function randomFill<T extends ArrayBufferView | ArrayBufferLike>(
|
|
141
155
|
buffer: T,
|
|
142
156
|
callback: (error: Error | null, buffer: T) => void
|
|
143
157
|
): void;
|
|
144
|
-
|
|
158
|
+
function randomFill<T extends ArrayBufferView | ArrayBufferLike>(
|
|
145
159
|
buffer: T,
|
|
146
160
|
offset: number,
|
|
147
161
|
callback: (error: Error | null, buffer: T) => void
|
|
148
162
|
): void;
|
|
149
|
-
|
|
163
|
+
function randomFill<T extends ArrayBufferView | ArrayBufferLike>(
|
|
150
164
|
buffer: T,
|
|
151
165
|
offset: number,
|
|
152
166
|
size: number,
|
|
153
167
|
callback: (error: Error | null, buffer: T) => void
|
|
154
168
|
): void;
|
|
155
|
-
|
|
169
|
+
function randomFill(
|
|
156
170
|
buffer: unknown,
|
|
157
171
|
offsetOrCallback?: unknown,
|
|
158
172
|
sizeOrCallback?: unknown,
|
|
@@ -191,24 +205,24 @@ export function randomFill(
|
|
|
191
205
|
});
|
|
192
206
|
}
|
|
193
207
|
|
|
194
|
-
|
|
208
|
+
function randomUUID(): string {
|
|
195
209
|
return crypto.randomUUID();
|
|
196
210
|
}
|
|
197
211
|
|
|
198
212
|
/** Node's `randomInt` draws from six bytes, so this is its largest range. */
|
|
199
213
|
const kRandMax = 281474976710655;
|
|
200
214
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
215
|
+
function randomInt(max: number): number;
|
|
216
|
+
function randomInt(min: number, max: number): number;
|
|
217
|
+
function randomInt(max: number, callback: (error: undefined, value: number) => void): void;
|
|
218
|
+
function randomInt(min: number, max: number, callback: (error: undefined, value: number) => void): void;
|
|
205
219
|
/**
|
|
206
220
|
* Node's `randomInt`, transcribed: an unbiased draw by rejection, Node's
|
|
207
221
|
* argument checks, and the callback form. The engine had neither the callback
|
|
208
222
|
* form nor the checks, so `randomInt(3, cb)` read the callback as the maximum
|
|
209
223
|
* and answered NaN, and `randomInt(1, 1)` divided by a zero range.
|
|
210
224
|
*/
|
|
211
|
-
|
|
225
|
+
function randomInt(
|
|
212
226
|
min: number,
|
|
213
227
|
max?: number | ((error: undefined, value: number) => void),
|
|
214
228
|
callback?: (error: undefined, value: number) => void
|
|
@@ -250,7 +264,7 @@ export function randomInt(
|
|
|
250
264
|
}
|
|
251
265
|
}
|
|
252
266
|
|
|
253
|
-
|
|
267
|
+
function getRandomValues<T extends ArrayBufferView>(array: T): T {
|
|
254
268
|
return crypto.getRandomValues(array);
|
|
255
269
|
}
|
|
256
270
|
|
|
@@ -269,12 +283,7 @@ export function getRandomValues<T extends ArrayBufferView>(array: T): T {
|
|
|
269
283
|
// MD5; both are pure JS and byte-for-byte Node's.
|
|
270
284
|
|
|
271
285
|
/** A hash engine: sha.js's Hash, or @noble/hashes' MD5. */
|
|
272
|
-
|
|
273
|
-
update(data: Uint8Array): DigestState;
|
|
274
|
-
digest(): Uint8Array;
|
|
275
|
-
clone?(): DigestState;
|
|
276
|
-
[field: string]: unknown;
|
|
277
|
-
}
|
|
286
|
+
|
|
278
287
|
|
|
279
288
|
const HASH_ALGORITHMS = ['md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512'];
|
|
280
289
|
|
|
@@ -290,7 +299,7 @@ function finalized(): Error {
|
|
|
290
299
|
* Node throws ERR_CRYPTO_UNSUPPORTED_OPERATION rather than returning
|
|
291
300
|
* something that only looks like a result; so does this shim.
|
|
292
301
|
*/
|
|
293
|
-
|
|
302
|
+
function unsupported(operation: string): never {
|
|
294
303
|
throw cryptoError(
|
|
295
304
|
'ERR_CRYPTO_UNSUPPORTED_OPERATION',
|
|
296
305
|
`${operation} is not supported by the browser crypto adapter.`
|
|
@@ -355,27 +364,27 @@ function digestResult(value: Uint8Array, encoding?: string): Buffer | string {
|
|
|
355
364
|
}
|
|
356
365
|
|
|
357
366
|
class Hash {
|
|
358
|
-
|
|
359
|
-
|
|
367
|
+
#state: DigestState;
|
|
368
|
+
#done = false;
|
|
360
369
|
readonly algorithm: string;
|
|
361
370
|
|
|
362
371
|
constructor(algorithm: string) {
|
|
363
372
|
this.algorithm = algorithm;
|
|
364
|
-
this
|
|
373
|
+
this.#state = digestEngine(algorithm);
|
|
365
374
|
}
|
|
366
375
|
|
|
367
376
|
update(data: unknown, inputEncoding?: string): this {
|
|
368
|
-
if (this
|
|
377
|
+
if (this.#done) throw finalized();
|
|
369
378
|
// Consume the bytes now: Node's update copies, and a caller may reuse
|
|
370
379
|
// the array it handed us before digest().
|
|
371
|
-
this
|
|
380
|
+
this.#state.update(cryptoBytes(data, inputEncoding));
|
|
372
381
|
return this;
|
|
373
382
|
}
|
|
374
383
|
|
|
375
384
|
digest(outputEncoding?: string): Buffer | string {
|
|
376
|
-
if (this
|
|
377
|
-
this
|
|
378
|
-
return digestResult(this
|
|
385
|
+
if (this.#done) throw finalized();
|
|
386
|
+
this.#done = true;
|
|
387
|
+
return digestResult(this.#state.digest(), outputEncoding);
|
|
379
388
|
}
|
|
380
389
|
|
|
381
390
|
async digestAsync(outputEncoding?: string): Promise<Buffer | string> {
|
|
@@ -383,17 +392,17 @@ class Hash {
|
|
|
383
392
|
}
|
|
384
393
|
|
|
385
394
|
copy(): Hash {
|
|
386
|
-
if (this
|
|
395
|
+
if (this.#done) throw finalized();
|
|
387
396
|
const copy = new Hash(this.algorithm);
|
|
388
|
-
if (this
|
|
389
|
-
copy
|
|
397
|
+
if (this.#state.clone) {
|
|
398
|
+
copy.#state = this.#state.clone();
|
|
390
399
|
return copy;
|
|
391
400
|
}
|
|
392
401
|
// sha.js 2.4.12 keeps its chaining words, length and current block in own
|
|
393
402
|
// fields and offers no clone. Copy buffers and scratch arrays by value;
|
|
394
403
|
// everything else is a number.
|
|
395
|
-
for (const [field, value] of Object.entries(this
|
|
396
|
-
copy
|
|
404
|
+
for (const [field, value] of Object.entries(this.#state)) {
|
|
405
|
+
copy.#state[field] = ArrayBuffer.isView(value)
|
|
397
406
|
? HostBuffer.from(cryptoBytes(value))
|
|
398
407
|
: Array.isArray(value)
|
|
399
408
|
? value.slice()
|
|
@@ -404,9 +413,9 @@ class Hash {
|
|
|
404
413
|
}
|
|
405
414
|
|
|
406
415
|
class Hmac {
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
416
|
+
#inner: DigestState;
|
|
417
|
+
#outer: DigestState;
|
|
418
|
+
#done = false;
|
|
410
419
|
|
|
411
420
|
constructor(algorithm: string, key: HostBytes) {
|
|
412
421
|
const blockSize = algorithm === 'sha384' || algorithm === 'sha512' ? 128 : 64;
|
|
@@ -420,23 +429,23 @@ class Hmac {
|
|
|
420
429
|
innerPad[index] = byte ^ 0x36;
|
|
421
430
|
outerPad[index] = byte ^ 0x5c;
|
|
422
431
|
}
|
|
423
|
-
this
|
|
424
|
-
this
|
|
432
|
+
this.#inner = digestEngine(algorithm).update(innerPad);
|
|
433
|
+
this.#outer = digestEngine(algorithm).update(outerPad);
|
|
425
434
|
innerPad.fill(0);
|
|
426
435
|
outerPad.fill(0);
|
|
427
436
|
}
|
|
428
437
|
|
|
429
438
|
update(data: unknown, inputEncoding?: string): this {
|
|
430
|
-
if (this
|
|
431
|
-
this
|
|
439
|
+
if (this.#done) throw finalized();
|
|
440
|
+
this.#inner.update(cryptoBytes(data, inputEncoding));
|
|
432
441
|
return this;
|
|
433
442
|
}
|
|
434
443
|
|
|
435
444
|
digest(outputEncoding?: string): Buffer | string {
|
|
436
445
|
// Node's Hmac yields an empty result from a second digest(), not an error.
|
|
437
|
-
if (this
|
|
438
|
-
this
|
|
439
|
-
return digestResult(this
|
|
446
|
+
if (this.#done) return digestResult(HostBuffer.alloc(0), outputEncoding);
|
|
447
|
+
this.#done = true;
|
|
448
|
+
return digestResult(this.#outer.update(this.#inner.digest()).digest(), outputEncoding);
|
|
440
449
|
}
|
|
441
450
|
|
|
442
451
|
async digestAsync(outputEncoding?: string): Promise<Buffer | string> {
|
|
@@ -444,12 +453,12 @@ class Hmac {
|
|
|
444
453
|
}
|
|
445
454
|
}
|
|
446
455
|
|
|
447
|
-
|
|
456
|
+
function createHash(algorithm: string, options?: { outputLength?: number }): Hash {
|
|
448
457
|
if (options?.outputLength !== undefined) unsupported('Variable-length digests');
|
|
449
458
|
return new Hash(hashAlgorithm(algorithm));
|
|
450
459
|
}
|
|
451
460
|
|
|
452
|
-
|
|
461
|
+
function createHmac(
|
|
453
462
|
algorithm: string,
|
|
454
463
|
key: unknown,
|
|
455
464
|
options?: { encoding?: string }
|
|
@@ -467,7 +476,7 @@ export function createHmac(
|
|
|
467
476
|
}
|
|
468
477
|
|
|
469
478
|
/** The one-shot digest, `crypto.hash`, added in Node 21. */
|
|
470
|
-
|
|
479
|
+
function hash(algorithm: string, data: unknown, outputEncoding = 'hex'): Buffer | string {
|
|
471
480
|
return createHash(algorithm).update(data).digest(outputEncoding);
|
|
472
481
|
}
|
|
473
482
|
|
|
@@ -541,7 +550,7 @@ function derive(parameters: Pbkdf2Parameters): Buffer {
|
|
|
541
550
|
}
|
|
542
551
|
}
|
|
543
552
|
|
|
544
|
-
|
|
553
|
+
function pbkdf2Sync(
|
|
545
554
|
password: BinaryLike,
|
|
546
555
|
salt: BinaryLike,
|
|
547
556
|
iterations: number,
|
|
@@ -551,7 +560,7 @@ export function pbkdf2Sync(
|
|
|
551
560
|
return derive(pbkdf2Parameters(password, salt, iterations, keylen, digest));
|
|
552
561
|
}
|
|
553
562
|
|
|
554
|
-
|
|
563
|
+
function pbkdf2(
|
|
555
564
|
password: BinaryLike,
|
|
556
565
|
salt: BinaryLike,
|
|
557
566
|
iterations: number,
|
|
@@ -583,7 +592,7 @@ export function pbkdf2(
|
|
|
583
592
|
* Calculates and returns a signature for data using the given private key
|
|
584
593
|
* This is the one-shot API that jose uses
|
|
585
594
|
*/
|
|
586
|
-
|
|
595
|
+
function sign(
|
|
587
596
|
algorithm: string | null | undefined,
|
|
588
597
|
data: Buffer | Uint8Array,
|
|
589
598
|
key: KeyLike,
|
|
@@ -619,7 +628,7 @@ export function sign(
|
|
|
619
628
|
/**
|
|
620
629
|
* Verifies the given signature for data using the given key
|
|
621
630
|
*/
|
|
622
|
-
|
|
631
|
+
function verify(
|
|
623
632
|
algorithm: string | null | undefined,
|
|
624
633
|
data: Buffer | Uint8Array,
|
|
625
634
|
key: KeyLike,
|
|
@@ -652,33 +661,33 @@ export function verify(
|
|
|
652
661
|
// createSign / createVerify (streaming API)
|
|
653
662
|
// ============================================================================
|
|
654
663
|
|
|
655
|
-
|
|
664
|
+
function createSign(algorithm: string): Sign {
|
|
656
665
|
return new Sign(algorithm);
|
|
657
666
|
}
|
|
658
667
|
|
|
659
|
-
|
|
668
|
+
function createVerify(algorithm: string): Verify {
|
|
660
669
|
return new Verify(algorithm);
|
|
661
670
|
}
|
|
662
671
|
|
|
663
672
|
class Sign extends EventEmitter {
|
|
664
|
-
|
|
665
|
-
|
|
673
|
+
#algorithm: string;
|
|
674
|
+
#data: Uint8Array[] = [];
|
|
666
675
|
|
|
667
676
|
constructor(algorithm: string) {
|
|
668
677
|
super();
|
|
669
|
-
this
|
|
678
|
+
this.#algorithm = algorithm;
|
|
670
679
|
}
|
|
671
680
|
|
|
672
681
|
update(data: string | Buffer | Uint8Array, encoding?: string): this {
|
|
673
682
|
const buffer = typeof data === 'string' ? Buffer.from(data) : data;
|
|
674
|
-
this
|
|
683
|
+
this.#data.push(buffer);
|
|
675
684
|
return this;
|
|
676
685
|
}
|
|
677
686
|
|
|
678
687
|
sign(privateKey: KeyLike, outputEncoding?: string): Buffer | string {
|
|
679
|
-
const combined = concatBuffers(this
|
|
688
|
+
const combined = concatBuffers(this.#data);
|
|
680
689
|
const keyInfo = extractKeyInfo(privateKey);
|
|
681
|
-
const signature = signSync(this
|
|
690
|
+
const signature = signSync(this.#algorithm, combined, keyInfo);
|
|
682
691
|
|
|
683
692
|
if (outputEncoding === 'base64') {
|
|
684
693
|
return btoa(String.fromCharCode(...signature));
|
|
@@ -691,22 +700,22 @@ class Sign extends EventEmitter {
|
|
|
691
700
|
}
|
|
692
701
|
|
|
693
702
|
class Verify extends EventEmitter {
|
|
694
|
-
|
|
695
|
-
|
|
703
|
+
#algorithm: string;
|
|
704
|
+
#data: Uint8Array[] = [];
|
|
696
705
|
|
|
697
706
|
constructor(algorithm: string) {
|
|
698
707
|
super();
|
|
699
|
-
this
|
|
708
|
+
this.#algorithm = algorithm;
|
|
700
709
|
}
|
|
701
710
|
|
|
702
711
|
update(data: string | Buffer | Uint8Array, encoding?: string): this {
|
|
703
712
|
const buffer = typeof data === 'string' ? Buffer.from(data) : data;
|
|
704
|
-
this
|
|
713
|
+
this.#data.push(buffer);
|
|
705
714
|
return this;
|
|
706
715
|
}
|
|
707
716
|
|
|
708
717
|
verify(publicKey: KeyLike, signature: Buffer | string, signatureEncoding?: string): boolean {
|
|
709
|
-
const combined = concatBuffers(this
|
|
718
|
+
const combined = concatBuffers(this.#data);
|
|
710
719
|
const keyInfo = extractKeyInfo(publicKey);
|
|
711
720
|
|
|
712
721
|
let sig: Buffer;
|
|
@@ -722,7 +731,7 @@ class Verify extends EventEmitter {
|
|
|
722
731
|
sig = signature;
|
|
723
732
|
}
|
|
724
733
|
|
|
725
|
-
return verifySync(this
|
|
734
|
+
return verifySync(this.#algorithm, combined, keyInfo, sig);
|
|
726
735
|
}
|
|
727
736
|
}
|
|
728
737
|
|
|
@@ -730,59 +739,63 @@ class Verify extends EventEmitter {
|
|
|
730
739
|
// KeyObject class (for key management)
|
|
731
740
|
// ============================================================================
|
|
732
741
|
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
742
|
+
let keyInfoOf: (key: KeyObject) => KeyInfo;
|
|
743
|
+
class KeyObject {
|
|
744
|
+
static {
|
|
745
|
+
keyInfoOf = (key) => ({ keyData: key.#_keyData, algorithm: key.#_algorithm, type: key.#_type, format: 'raw' });
|
|
746
|
+
}
|
|
747
|
+
#_keyData: CryptoKey | Uint8Array;
|
|
748
|
+
#_type: 'public' | 'private' | 'secret';
|
|
749
|
+
#_algorithm?: string;
|
|
737
750
|
|
|
738
751
|
constructor(type: 'public' | 'private' | 'secret', keyData: CryptoKey | Uint8Array, algorithm?: string) {
|
|
739
|
-
this
|
|
740
|
-
this
|
|
741
|
-
this
|
|
752
|
+
this.#_type = type;
|
|
753
|
+
this.#_keyData = keyData;
|
|
754
|
+
this.#_algorithm = algorithm;
|
|
742
755
|
}
|
|
743
756
|
|
|
744
757
|
get type(): string {
|
|
745
|
-
return this
|
|
758
|
+
return this.#_type;
|
|
746
759
|
}
|
|
747
760
|
|
|
748
761
|
get asymmetricKeyType(): string | undefined {
|
|
749
|
-
if (this
|
|
762
|
+
if (this.#_type === 'secret') return undefined;
|
|
750
763
|
// Infer from algorithm
|
|
751
|
-
if (this
|
|
752
|
-
if (this
|
|
753
|
-
if (this
|
|
764
|
+
if (this.#_algorithm?.includes('RSA')) return 'rsa';
|
|
765
|
+
if (this.#_algorithm?.includes('EC') || this.#_algorithm?.includes('ES')) return 'ec';
|
|
766
|
+
if (this.#_algorithm?.includes('Ed')) return 'ed25519';
|
|
754
767
|
return undefined;
|
|
755
768
|
}
|
|
756
769
|
|
|
757
770
|
get symmetricKeySize(): number | undefined {
|
|
758
|
-
if (this
|
|
759
|
-
if (this
|
|
760
|
-
return this
|
|
771
|
+
if (this.#_type !== 'secret') return undefined;
|
|
772
|
+
if (this.#_keyData instanceof Uint8Array) {
|
|
773
|
+
return this.#_keyData.length * 8;
|
|
761
774
|
}
|
|
762
775
|
return undefined;
|
|
763
776
|
}
|
|
764
777
|
|
|
765
778
|
export(options?: { type?: string; format?: string }): Buffer | string {
|
|
766
779
|
// Simplified export - returns the key data
|
|
767
|
-
if (this
|
|
768
|
-
return Buffer.from(this
|
|
780
|
+
if (this.#_keyData instanceof Uint8Array) {
|
|
781
|
+
return Buffer.from(this.#_keyData);
|
|
769
782
|
}
|
|
770
783
|
throw new Error('Cannot export CryptoKey synchronously');
|
|
771
784
|
}
|
|
772
785
|
}
|
|
773
786
|
|
|
774
|
-
|
|
787
|
+
function createSecretKey(key: BinaryLike | ArrayBufferView, encoding?: string): KeyObject {
|
|
775
788
|
// Node copies the key material, so a caller that reuses or zeroes its array
|
|
776
789
|
// does not change the key this object holds.
|
|
777
790
|
return new KeyObject('secret', Buffer.from(cryptoBytes(key, encoding, true)));
|
|
778
791
|
}
|
|
779
792
|
|
|
780
|
-
|
|
793
|
+
function createPublicKey(key: KeyLike): KeyObject {
|
|
781
794
|
const keyInfo = extractKeyInfo(key);
|
|
782
795
|
return new KeyObject('public', keyInfo.keyData as Uint8Array, keyInfo.algorithm);
|
|
783
796
|
}
|
|
784
797
|
|
|
785
|
-
|
|
798
|
+
function createPrivateKey(key: KeyLike): KeyObject {
|
|
786
799
|
const keyInfo = extractKeyInfo(key);
|
|
787
800
|
return new KeyObject('private', keyInfo.keyData as Uint8Array, keyInfo.algorithm);
|
|
788
801
|
}
|
|
@@ -791,7 +804,7 @@ export function createPrivateKey(key: KeyLike): KeyObject {
|
|
|
791
804
|
// Utility functions
|
|
792
805
|
// ============================================================================
|
|
793
806
|
|
|
794
|
-
|
|
807
|
+
function timingSafeEqual(a: Buffer | Uint8Array, b: Buffer | Uint8Array): boolean {
|
|
795
808
|
if (a.length !== b.length) {
|
|
796
809
|
return false;
|
|
797
810
|
}
|
|
@@ -802,11 +815,11 @@ export function timingSafeEqual(a: Buffer | Uint8Array, b: Buffer | Uint8Array):
|
|
|
802
815
|
return result === 0;
|
|
803
816
|
}
|
|
804
817
|
|
|
805
|
-
|
|
818
|
+
function getCiphers(): string[] {
|
|
806
819
|
return ['aes-128-cbc', 'aes-256-cbc', 'aes-128-gcm', 'aes-256-gcm'];
|
|
807
820
|
}
|
|
808
821
|
|
|
809
|
-
|
|
822
|
+
function getHashes(): string[] {
|
|
810
823
|
// What createHash accepts, no more: a name here that createHash rejects
|
|
811
824
|
// sends a guest down a branch that then throws.
|
|
812
825
|
return HASH_ALGORITHMS.slice();
|
|
@@ -862,12 +875,7 @@ function getWebCryptoAlgorithm(nodeAlgorithm: string): { name: string; hash?: st
|
|
|
862
875
|
|
|
863
876
|
function extractKeyInfo(key: KeyLike): KeyInfo {
|
|
864
877
|
if (key instanceof KeyObject) {
|
|
865
|
-
return
|
|
866
|
-
keyData: (key as any)._keyData,
|
|
867
|
-
algorithm: (key as any)._algorithm,
|
|
868
|
-
type: (key as any)._type,
|
|
869
|
-
format: 'raw',
|
|
870
|
-
};
|
|
878
|
+
return keyInfoOf(key);
|
|
871
879
|
}
|
|
872
880
|
|
|
873
881
|
if (typeof key === 'object' && 'key' in key) {
|
|
@@ -1034,7 +1042,8 @@ async function importKey(
|
|
|
1034
1042
|
// Exports
|
|
1035
1043
|
// ============================================================================
|
|
1036
1044
|
|
|
1037
|
-
|
|
1045
|
+
return {
|
|
1046
|
+
unsupported,
|
|
1038
1047
|
randomBytes,
|
|
1039
1048
|
randomFill,
|
|
1040
1049
|
randomFillSync,
|
|
@@ -1059,3 +1068,9 @@ export default {
|
|
|
1059
1068
|
createPublicKey,
|
|
1060
1069
|
createPrivateKey,
|
|
1061
1070
|
};
|
|
1071
|
+
|
|
1072
|
+
}
|
|
1073
|
+
const cryptoModule = createCryptoModule();
|
|
1074
|
+
export const { randomBytes, randomFillSync, randomFill, randomUUID, randomInt, getRandomValues, unsupported, createHash, createHmac, hash, pbkdf2Sync, pbkdf2, sign, verify, createSign, createVerify, KeyObject, createSecretKey, createPublicKey, createPrivateKey, timingSafeEqual, getCiphers, getHashes } = cryptoModule;
|
|
1075
|
+
export type KeyObject = InstanceType<typeof KeyObject>;
|
|
1076
|
+
export default cryptoModule;
|
package/src/shims/dns.ts
CHANGED
|
@@ -168,7 +168,7 @@ export const ADDRCONFIG = 0;
|
|
|
168
168
|
export const V4MAPPED = 0;
|
|
169
169
|
export const ALL = 0;
|
|
170
170
|
|
|
171
|
-
|
|
171
|
+
const dnsModule = {
|
|
172
172
|
lookup,
|
|
173
173
|
resolve,
|
|
174
174
|
resolve4,
|
|
@@ -183,3 +183,19 @@ export default {
|
|
|
183
183
|
V4MAPPED,
|
|
184
184
|
ALL,
|
|
185
185
|
};
|
|
186
|
+
|
|
187
|
+
const dnsCodes = {
|
|
188
|
+
NODATA: "ENODATA", FORMERR: "EFORMERR", SERVFAIL: "ESERVFAIL", NOTFOUND: "ENOTFOUND",
|
|
189
|
+
NOTIMP: "ENOTIMP", REFUSED: "EREFUSED", BADQUERY: "EBADQUERY", BADNAME: "EBADNAME",
|
|
190
|
+
BADFAMILY: "EBADFAMILY", BADRESP: "EBADRESP", CONNREFUSED: "ECONNREFUSED", TIMEOUT: "ETIMEOUT",
|
|
191
|
+
EOF: "EOF", FILE: "EFILE", NOMEM: "ENOMEM", DESTRUCTION: "EDESTRUCTION", BADSTR: "EBADSTR",
|
|
192
|
+
BADFLAGS: "EBADFLAGS", NONAME: "ENONAME", BADHINTS: "EBADHINTS", NOTINITIALIZED: "ENOTINITIALIZED",
|
|
193
|
+
LOADIPHLPAPI: "ELOADIPHLPAPI", ADDRGETNETWORKPARAMS: "EADDRGETNETWORKPARAMS", CANCELLED: "ECANCELLED"
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
export function createDnsModule() {
|
|
197
|
+
const promiseModule = { ...promises, ...dnsCodes };
|
|
198
|
+
return { ...dnsModule, ...dnsCodes, promises: promiseModule };
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export default dnsModule;
|
package/src/shims/process.ts
CHANGED
|
@@ -7,8 +7,10 @@
|
|
|
7
7
|
import { EventEmitter } from '../node-lib/events-module';
|
|
8
8
|
import type { EventListener } from '../node-lib/events-module';
|
|
9
9
|
import { Readable } from '../node-lib/stream-module';
|
|
10
|
+
import { loadNodeLibFor } from '../node-lib/load';
|
|
10
11
|
import { constantsBinding } from './constants';
|
|
11
|
-
import
|
|
12
|
+
import ttyWrapBinding from '../node-lib/binding/tty_wrap';
|
|
13
|
+
import { mintPid, pidIsLive, signalPid } from '../process-tokens';
|
|
12
14
|
import { NODE_LTS_VERSION, nodeVersions } from '../node-lib/node-versions';
|
|
13
15
|
import { freemem as osFreemem } from './os';
|
|
14
16
|
|
|
@@ -98,9 +100,12 @@ export interface ProcessStdin extends Readable {
|
|
|
98
100
|
}
|
|
99
101
|
|
|
100
102
|
// eslint-disable-next-line no-var, vars-on-top
|
|
101
|
-
var
|
|
102
|
-
function processStdinClass(): new () => ProcessStdin {
|
|
103
|
-
|
|
103
|
+
var StdinClasses: WeakMap<object, new () => ProcessStdin> | undefined;
|
|
104
|
+
function processStdinClass(ReadableClass: typeof Readable): new () => ProcessStdin {
|
|
105
|
+
StdinClasses ??= new WeakMap();
|
|
106
|
+
const cached = StdinClasses.get(ReadableClass);
|
|
107
|
+
if (cached) return cached;
|
|
108
|
+
const StdinClass = class ProcessStdin extends (ReadableClass as unknown as new () => Readable) {
|
|
104
109
|
/** Node's fd for standard input. */
|
|
105
110
|
readonly fd = 0;
|
|
106
111
|
|
|
@@ -125,12 +130,15 @@ function processStdinClass(): new () => ProcessStdin {
|
|
|
125
130
|
this.push(null);
|
|
126
131
|
}
|
|
127
132
|
} as unknown as new () => ProcessStdin;
|
|
133
|
+
StdinClasses.set(ReadableClass, StdinClass);
|
|
134
|
+
return StdinClass;
|
|
128
135
|
}
|
|
129
136
|
|
|
130
137
|
type ProcessReadableStream = ProcessStdin;
|
|
131
138
|
|
|
132
139
|
export interface Process {
|
|
133
140
|
env: ProcessEnv;
|
|
141
|
+
title: string;
|
|
134
142
|
cwd: () => string;
|
|
135
143
|
chdir: (directory: string) => void;
|
|
136
144
|
platform: string;
|
|
@@ -469,12 +477,13 @@ export function createProcess(options?: {
|
|
|
469
477
|
const startTime = Date.now();
|
|
470
478
|
// The guest's fd 0: the bytes the runner put there, then the end of them.
|
|
471
479
|
// Nothing more can arrive unless the runner says it holds the input open.
|
|
472
|
-
|
|
473
|
-
if (typeof options?.stdin === 'string') stdinStream.__substrateStdinWrite(options.stdin);
|
|
474
|
-
if (!options?.stdinHeld) stdinStream.__substrateStdinEnd();
|
|
480
|
+
let stdinStream: ProcessStdin | undefined;
|
|
475
481
|
|
|
476
482
|
const proc: Process = {
|
|
477
483
|
env,
|
|
484
|
+
// Node exposes a writable title even before application code sets it.
|
|
485
|
+
// Packages use its presence when distinguishing Node from a browser.
|
|
486
|
+
title: 'node',
|
|
478
487
|
|
|
479
488
|
cwd() {
|
|
480
489
|
return currentDir;
|
|
@@ -547,9 +556,10 @@ export function createProcess(options?: {
|
|
|
547
556
|
if (signal !== 0 && (typeof name !== "string" || __substrateSignals[name] === void 0)) {
|
|
548
557
|
throw Object.assign(new TypeError("Unknown signal: " + signal), { code: "ERR_UNKNOWN_SIGNAL" });
|
|
549
558
|
}
|
|
550
|
-
//
|
|
551
|
-
//
|
|
552
|
-
//
|
|
559
|
+
// A signal to the guest's own pid is raised on its own process object
|
|
560
|
+
// the way Node raises one; its children take theirs through their
|
|
561
|
+
// handles, other live processes of the container through the process
|
|
562
|
+
// registry, and every other pid is ESRCH rather than a silent success.
|
|
553
563
|
if (pid !== proc.pid) {
|
|
554
564
|
const child = __substrateChildren.get(Math.abs(pid));
|
|
555
565
|
if (child === void 0 || child.exitCode !== null || child.signalCode !== null) {
|
|
@@ -558,6 +568,10 @@ export function createProcess(options?: {
|
|
|
558
568
|
// of a lock file, a parent's. A live run answers yes and carries no
|
|
559
569
|
// signal; anything else is `ESRCH`, as it is on a machine.
|
|
560
570
|
if (signal === 0 && pidIsLive(Math.abs(pid))) return true;
|
|
571
|
+
// Any other live process of the container takes the signal too,
|
|
572
|
+
// including one whose parent has exited; otherwise nothing could
|
|
573
|
+
// ever end it.
|
|
574
|
+
if (signal !== 0 && child === void 0 && pid > 0 && signalPid(pid, name)) return true;
|
|
561
575
|
throw Object.assign(new Error("kill ESRCH"), { code: "ESRCH", errno: -3, syscall: "kill" });
|
|
562
576
|
}
|
|
563
577
|
if (signal === 0) return true;
|
|
@@ -593,6 +607,7 @@ export function createProcess(options?: {
|
|
|
593
607
|
proc.emitWarning("process.binding() is deprecated. Please use public APIs instead.", "DeprecationWarning", "DEP0111");
|
|
594
608
|
}
|
|
595
609
|
if (name === "constants") return constantsBinding();
|
|
610
|
+
if (name === "tty_wrap") return ttyWrapBinding;
|
|
596
611
|
throw new Error("No such module: " + name);
|
|
597
612
|
},
|
|
598
613
|
|
|
@@ -655,7 +670,14 @@ export function createProcess(options?: {
|
|
|
655
670
|
return true;
|
|
656
671
|
}) as ProcessWritableStream,
|
|
657
672
|
|
|
658
|
-
stdin
|
|
673
|
+
get stdin() {
|
|
674
|
+
if (!stdinStream) {
|
|
675
|
+
stdinStream = new (processStdinClass(loadNodeLibFor(proc, 'stream').Readable))();
|
|
676
|
+
if (typeof options?.stdin === 'string') stdinStream.__substrateStdinWrite(options.stdin);
|
|
677
|
+
if (!options?.stdinHeld) stdinStream.__substrateStdinEnd();
|
|
678
|
+
}
|
|
679
|
+
return stdinStream;
|
|
680
|
+
},
|
|
659
681
|
|
|
660
682
|
hrtime: Object.assign(
|
|
661
683
|
function hrtime(time?: [number, number]): [number, number] {
|