cf-workers-native 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/browser/documents/page-source.js +1 -1
- package/dist/browser/fetch/host-call.js +6 -1
- package/dist/browser/fetch/native-network.d.ts +1 -1
- package/dist/browser/fetch/relay.js +2 -0
- package/dist/browser/headers/index.d.ts +2 -0
- package/dist/browser/headers/index.js +5 -0
- package/dist/browser/isolated/transport.js +3 -2
- package/dist/browser/request/index.js +3 -2
- package/dist/browser/response/index.d.ts +2 -0
- package/dist/browser/response/index.js +11 -3
- package/dist/browser/structured-clone/index.d.ts +3 -0
- package/dist/browser/structured-clone/index.js +75 -7
- package/dist/browser/websocket/attachment-size.d.ts +3 -0
- package/dist/browser/websocket/attachment-size.js +336 -0
- package/dist/browser/websocket/brand.d.ts +4 -0
- package/dist/browser/websocket/brand.js +16 -0
- package/dist/browser/websocket/close-event.d.ts +7 -0
- package/dist/browser/websocket/close-event.js +30 -0
- package/dist/browser/websocket/compression.d.ts +5 -0
- package/dist/browser/websocket/compression.js +124 -0
- package/dist/browser/websocket/conversion.d.ts +2 -0
- package/dist/browser/websocket/conversion.js +13 -0
- package/dist/browser/websocket/endpoint.d.ts +39 -0
- package/dist/browser/websocket/endpoint.js +379 -0
- package/dist/browser/websocket/frames.d.ts +21 -0
- package/dist/browser/websocket/frames.js +121 -0
- package/dist/browser/websocket/native.d.ts +14 -0
- package/dist/browser/websocket/native.js +226 -0
- package/dist/cloudflare/apis/cloudflare-node/index.js +11 -23
- package/dist/cloudflare/workers/worker-runtime.js +2 -1
- package/dist/compat/console/index.d.ts +35 -0
- package/dist/compat/console/index.js +92 -0
- package/dist/compat/crypto/LICENSE-3RD-PARTY.md +39 -0
- package/dist/compat/crypto/LICENSE-APACHE +177 -0
- package/dist/compat/crypto/LICENSE.boringssl +238 -0
- package/dist/compat/crypto/LICENSE.emscripten +102 -0
- package/dist/compat/crypto/LICENSE.musl +193 -0
- package/dist/compat/crypto/LICENSE.ncrypto +21 -0
- package/dist/compat/crypto/LICENSE.openssl +177 -0
- package/dist/compat/crypto/asymmetric.d.ts +13 -0
- package/dist/compat/crypto/asymmetric.js +312 -0
- package/dist/compat/crypto/brorand.cjs +74 -0
- package/dist/compat/crypto/brorand.d.cts +6 -0
- package/dist/compat/crypto/certificate.d.ts +14 -0
- package/dist/compat/crypto/certificate.js +66 -0
- package/dist/compat/crypto/cipher-handle.d.ts +27 -0
- package/dist/compat/crypto/cipher-handle.js +239 -0
- package/dist/compat/crypto/cipher-info.d.ts +12 -0
- package/dist/compat/crypto/cipher-info.js +324 -0
- package/dist/compat/crypto/constants.d.ts +62 -0
- package/dist/compat/crypto/constants.js +68 -0
- package/dist/compat/crypto/dh-handle.d.ts +17 -0
- package/dist/compat/crypto/dh-handle.js +180 -0
- package/dist/compat/crypto/dh.d.ts +53 -0
- package/dist/compat/crypto/dh.js +138 -0
- package/dist/compat/crypto/digest-stream.d.ts +15 -0
- package/dist/compat/crypto/digest-stream.js +213 -0
- package/dist/compat/crypto/digests.d.ts +3 -0
- package/dist/compat/crypto/digests.js +32 -0
- package/dist/compat/crypto/ecdh.d.ts +25 -0
- package/dist/compat/crypto/ecdh.js +109 -0
- package/dist/compat/crypto/hash-handle.d.ts +23 -0
- package/dist/compat/crypto/hash-handle.js +70 -0
- package/dist/compat/crypto/hash.d.ts +37 -0
- package/dist/compat/crypto/hash.js +218 -0
- package/dist/compat/crypto/hkdf.d.ts +2 -0
- package/dist/compat/crypto/hkdf.js +78 -0
- package/dist/compat/crypto/index.cjs +2 -0
- package/dist/compat/crypto/index.d.cts +169 -0
- package/dist/compat/crypto/index.d.ts +213 -0
- package/dist/compat/crypto/index.js +96 -0
- package/dist/compat/crypto/key-errors.d.ts +10 -0
- package/dist/compat/crypto/key-errors.js +17 -0
- package/dist/compat/crypto/key-export.d.ts +8 -0
- package/dist/compat/crypto/key-export.js +49 -0
- package/dist/compat/crypto/key-formats.d.ts +7 -0
- package/dist/compat/crypto/key-formats.js +251 -0
- package/dist/compat/crypto/key-options.d.ts +1 -0
- package/dist/compat/crypto/key-options.js +74 -0
- package/dist/compat/crypto/key-state.d.ts +10 -0
- package/dist/compat/crypto/key-state.js +4 -0
- package/dist/compat/crypto/keys.d.ts +58 -0
- package/dist/compat/crypto/keys.js +278 -0
- package/dist/compat/crypto/metadata.d.ts +13 -0
- package/dist/compat/crypto/metadata.js +109 -0
- package/dist/compat/crypto/native-cipher.d.ts +17 -0
- package/dist/compat/crypto/native-cipher.js +192 -0
- package/dist/compat/crypto/native-crypto.d.ts +81 -0
- package/dist/compat/crypto/native-crypto.js +681 -0
- package/dist/compat/crypto/pbkdf2-handle.d.ts +4 -0
- package/dist/compat/crypto/pbkdf2-handle.js +26 -0
- package/dist/compat/crypto/pbkdf2.d.ts +5 -0
- package/dist/compat/crypto/pbkdf2.js +60 -0
- package/dist/compat/crypto/prime.d.ts +19 -0
- package/dist/compat/crypto/prime.js +146 -0
- package/dist/compat/crypto/random.d.ts +18 -0
- package/dist/compat/crypto/random.js +203 -0
- package/dist/compat/crypto/rsa.d.ts +21 -0
- package/dist/compat/crypto/rsa.js +177 -0
- package/dist/compat/crypto/scrypt.d.ts +25 -0
- package/dist/compat/crypto/scrypt.js +152 -0
- package/dist/compat/crypto/sign-errors.d.ts +8 -0
- package/dist/compat/crypto/sign-errors.js +13 -0
- package/dist/compat/crypto/sign-handle.d.ts +22 -0
- package/dist/compat/crypto/sign-handle.js +149 -0
- package/dist/compat/crypto/signatures.d.ts +34 -0
- package/dist/compat/crypto/signatures.js +252 -0
- package/dist/compat/crypto/subtle-digest.d.ts +1 -0
- package/dist/compat/crypto/subtle-digest.js +56 -0
- package/dist/compat/crypto/symmetric.d.ts +45 -0
- package/dist/compat/crypto/symmetric.js +239 -0
- package/dist/compat/crypto/validation.d.ts +7 -0
- package/dist/compat/crypto/validation.js +46 -0
- package/dist/compat/crypto/webcrypto.d.ts +13 -0
- package/dist/compat/crypto/webcrypto.js +51 -0
- package/dist/compat/crypto/x509.d.ts +30 -0
- package/dist/compat/crypto/x509.js +407 -0
- package/dist/compat/events/errors.d.ts +8 -0
- package/dist/compat/events/errors.js +39 -0
- package/dist/compat/events/index.cjs +2 -0
- package/dist/compat/events/index.d.cts +2 -0
- package/dist/compat/events/index.d.ts +64 -0
- package/dist/compat/events/index.js +792 -0
- package/dist/compat/events/intrinsics.d.ts +1 -0
- package/dist/compat/events/intrinsics.js +2 -0
- package/dist/compat/fs/LICENSE-3RD-PARTY.md +11 -0
- package/dist/compat/fs/LICENSE-APACHE +177 -0
- package/dist/compat/fs/directory-backend.d.ts +6 -0
- package/dist/compat/fs/directory-backend.js +51 -0
- package/dist/compat/fs/directory.d.ts +37 -0
- package/dist/compat/fs/directory.js +137 -0
- package/dist/compat/fs/embedded.d.ts +85 -0
- package/dist/compat/fs/embedded.js +260 -0
- package/dist/compat/fs/file-handle.d.ts +75 -0
- package/dist/compat/fs/file-handle.js +226 -0
- package/dist/compat/fs/glob-internal.d.ts +15 -0
- package/dist/compat/fs/glob-internal.js +417 -0
- package/dist/compat/fs/glob.d.ts +10 -0
- package/dist/compat/fs/glob.js +71 -0
- package/dist/compat/fs/index.d.ts +8 -82
- package/dist/compat/fs/index.js +736 -238
- package/dist/compat/fs/io-validation.d.ts +14 -0
- package/dist/compat/fs/io-validation.js +130 -0
- package/dist/compat/fs/io.d.ts +1 -0
- package/dist/compat/fs/io.js +282 -0
- package/dist/compat/fs/mode.d.ts +1 -0
- package/dist/compat/fs/mode.js +13 -0
- package/dist/compat/fs/promises/index.d.ts +3 -1
- package/dist/compat/fs/promises/index.js +1 -1
- package/dist/compat/fs/public-types.d.ts +120 -0
- package/dist/compat/fs/public-types.js +1 -0
- package/dist/compat/fs/stream-errors.d.ts +6 -0
- package/dist/compat/fs/stream-errors.js +8 -0
- package/dist/compat/fs/stream-utils.d.ts +16 -0
- package/dist/compat/fs/stream-utils.js +29 -0
- package/dist/compat/fs/streams.d.ts +104 -0
- package/dist/compat/fs/streams.js +794 -0
- package/dist/compat/fs/writable.d.ts +14 -0
- package/dist/compat/fs/writable.js +532 -0
- package/dist/compat/http/index.d.ts +11 -28
- package/dist/compat/http/index.js +81 -125
- package/dist/compat/http/server-options.d.ts +1 -0
- package/dist/compat/http/server-options.js +87 -0
- package/dist/compat/http/symbols.d.ts +5 -0
- package/dist/compat/http/symbols.js +9 -0
- package/dist/compat/http/unique-headers.d.ts +1 -0
- package/dist/compat/http/unique-headers.js +21 -0
- package/dist/compat/http-common/index.d.ts +37 -0
- package/dist/compat/http-common/index.js +43 -0
- package/dist/compat/http-outgoing/index.d.ts +14 -0
- package/dist/compat/http-outgoing/index.js +17 -0
- package/dist/compat/http-server/index.d.ts +18 -0
- package/dist/compat/http-server/index.js +26 -0
- package/dist/compat/https/index.d.ts +4 -2
- package/dist/compat/module/builtins.d.ts +1 -0
- package/dist/compat/module/builtins.js +101 -0
- package/dist/compat/module/index.d.ts +4 -2
- package/dist/compat/module/index.js +22 -17
- package/dist/compat/module/metadata.d.ts +44 -0
- package/dist/compat/module/metadata.js +127 -0
- package/dist/compat/net/internal-net.js +4 -0
- package/dist/compat/net/sockets.d.ts +5 -0
- package/dist/compat/net/sockets.js +153 -14
- package/dist/compat/net/validators.d.ts +1 -0
- package/dist/compat/net/validators.js +8 -0
- package/dist/compat/process/configuration.d.ts +113 -0
- package/dist/compat/process/configuration.js +115 -0
- package/dist/compat/process/directory.d.ts +4 -0
- package/dist/compat/process/directory.js +28 -0
- package/dist/compat/process/files.d.ts +3 -0
- package/dist/compat/process/files.js +10 -0
- package/dist/compat/process/index.cjs +2 -0
- package/dist/compat/process/index.d.cts +4 -0
- package/dist/compat/process/index.d.ts +20 -0
- package/dist/compat/process/index.js +113 -0
- package/dist/compat/process/metadata.d.ts +135 -0
- package/dist/compat/process/metadata.js +251 -0
- package/dist/compat/process/scheduling.d.ts +2 -0
- package/dist/compat/process/scheduling.js +60 -0
- package/dist/compat/process/state.d.ts +4 -0
- package/dist/compat/process/state.js +5 -0
- package/dist/compat/process/stdio.d.ts +18 -0
- package/dist/compat/process/stdio.js +66 -0
- package/dist/compat/stream/destroy.d.ts +1 -0
- package/dist/compat/stream/destroy.js +21 -1
- package/dist/compat/stream/readable.js +10 -2
- package/dist/compat/stream-web/LICENSE +22 -0
- package/dist/compat/stream-web/ponyfill.d.ts +1 -1
- package/dist/compat/stream-web/ponyfill.js +2369 -1775
- package/dist/compat/stream-web/runtime.d.ts +1 -1
- package/dist/compat/stream-web/runtime.js +3 -2
- package/dist/compat/stream-wrap/LICENSE-3RD-PARTY.md +11 -0
- package/dist/compat/stream-wrap/LICENSE-APACHE +177 -0
- package/dist/compat/stream-wrap/index.d.ts +1 -0
- package/dist/compat/stream-wrap/index.js +1 -0
- package/dist/compat/tls/LICENSE-3RD-PARTY.md +11 -0
- package/dist/compat/tls/LICENSE-APACHE +177 -0
- package/dist/compat/tls/constants.d.ts +7 -0
- package/dist/compat/tls/constants.js +14 -0
- package/dist/compat/tls/errors.d.ts +35 -0
- package/dist/compat/tls/errors.js +68 -0
- package/dist/compat/tls/helpers.d.ts +9 -0
- package/dist/compat/tls/helpers.js +207 -0
- package/dist/compat/tls/index.d.ts +26 -0
- package/dist/compat/tls/index.js +50 -0
- package/dist/compat/tls/jsstream.d.ts +19 -0
- package/dist/compat/tls/jsstream.js +196 -0
- package/dist/compat/tls/native-session.d.ts +3 -0
- package/dist/compat/tls/native-session.js +187 -0
- package/dist/compat/tls/wrap.d.ts +65 -0
- package/dist/compat/tls/wrap.js +541 -0
- package/dist/compat/tls-wrap/LICENSE-3RD-PARTY.md +11 -0
- package/dist/compat/tls-wrap/LICENSE-APACHE +177 -0
- package/dist/compat/tls-wrap/index.d.ts +7 -0
- package/dist/compat/tls-wrap/index.js +3 -0
- package/dist/compat/util/index.js +43 -1
- package/dist/compat/util/inspect.js +5 -1
- package/dist/compat/util/types/index.d.ts +3 -0
- package/dist/compat/util/types/index.js +5 -0
- package/dist/compat/zlib/LICENSE-3RD-PARTY.md +11 -0
- package/dist/compat/zlib/LICENSE-APACHE +177 -0
- package/dist/compat/zlib/LICENSE.brotli +19 -0
- package/dist/compat/zlib/LICENSE.emscripten +102 -0
- package/dist/compat/zlib/LICENSE.musl +193 -0
- package/dist/compat/zlib/LICENSE.zlib +22 -0
- package/dist/compat/zlib/LICENSE.zstd +30 -0
- package/dist/compat/zlib/classic-base.cjs +600 -0
- package/dist/compat/zlib/classic-base.d.cts +39 -0
- package/dist/compat/zlib/classic-binding.d.ts +28 -0
- package/dist/compat/zlib/classic-binding.js +105 -0
- package/dist/compat/zlib/classic.d.ts +44 -0
- package/dist/compat/zlib/classic.js +199 -0
- package/dist/compat/zlib/codec-binding.d.ts +33 -0
- package/dist/compat/zlib/codec-binding.js +141 -0
- package/dist/compat/zlib/compression.d.ts +26 -0
- package/dist/compat/zlib/compression.js +170 -0
- package/dist/compat/zlib/constants.d.ts +172 -0
- package/dist/compat/zlib/constants.js +173 -0
- package/dist/compat/zlib/errors.d.ts +21 -0
- package/dist/compat/zlib/errors.js +32 -0
- package/dist/compat/zlib/index.d.ts +544 -0
- package/dist/compat/zlib/index.js +194 -0
- package/dist/compat/zlib/input.d.ts +16 -0
- package/dist/compat/zlib/input.js +132 -0
- package/dist/compat/zlib/native-codecs.d.ts +24 -0
- package/dist/compat/zlib/native-codecs.js +180 -0
- package/dist/compat/zlib/native-zlib.d.ts +5 -0
- package/dist/compat/zlib/native-zlib.js +52 -0
- package/dist/compat/zlib/public-types.d.ts +48 -0
- package/dist/compat/zlib/public-types.js +1 -0
- package/dist/compat/zlib/validators.d.ts +3 -0
- package/dist/compat/zlib/validators.js +18 -0
- package/dist/shared/buffer-source.d.ts +5 -0
- package/dist/shared/buffer-source.js +70 -0
- package/dist/shared/globals/inject.d.ts +2 -1
- package/dist/shared/globals/inject.js +2 -1
- package/dist/shared/globals/platform.d.ts +8 -0
- package/dist/shared/globals/platform.js +1 -0
- package/dist/shared/globals/runtime.d.ts +1 -2
- package/dist/shared/globals/runtime.js +1 -2
- package/dist/shared/globals/web.js +5 -0
- package/dist/shared/request-context.d.ts +2 -0
- package/dist/shared/request-context.js +11 -0
- package/dist/shared/request-scope.d.ts +4 -0
- package/dist/shared/request-scope.js +14 -0
- package/dist/tooling/async.js +36 -14
- package/dist/tooling/shared.d.ts +1 -0
- package/dist/tooling/shared.js +26 -1
- package/dist/tooling/vite.js +8 -3
- package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkerSockets.java +92 -13
- package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkersCapacitorPlugin.java +4 -2
- package/native/ios/NetworkBridge.swift +11 -1
- package/native/ios/SocketBridge.swift +37 -2
- package/native/ios/WorkersCapacitorPlugin.swift +4 -0
- package/package.json +4 -2
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { installDigest } from "./subtle-digest.js";
|
|
2
|
+
import { installResourceSymbols } from "../../shared/globals/symbols.js";
|
|
3
|
+
import { viewBytes } from "./validation.js";
|
|
4
|
+
import { DigestStream } from "./digest-stream.js";
|
|
5
|
+
import { nativeTimingEqual } from "./native-crypto.js";
|
|
6
|
+
import { Buffer } from "node:buffer";
|
|
7
|
+
installResourceSymbols(globalThis.Symbol);
|
|
8
|
+
export const webcrypto = globalThis.crypto;
|
|
9
|
+
export const subtle = webcrypto.subtle;
|
|
10
|
+
installDigest(subtle);
|
|
11
|
+
function source(value, parameter) {
|
|
12
|
+
if (ArrayBuffer.isView(value))
|
|
13
|
+
return viewBytes(value);
|
|
14
|
+
try {
|
|
15
|
+
Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get.call(value);
|
|
16
|
+
try {
|
|
17
|
+
return Buffer.from(value);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return new Uint8Array(0);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
throw new TypeError(`Failed to execute 'timingSafeEqual' on 'SubtleCrypto': parameter ${parameter} is not of type 'BufferSource'.`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function timingSafeEqual(left, right) {
|
|
28
|
+
if (this !== subtle)
|
|
29
|
+
throw new TypeError("Illegal invocation: function called with incorrect `this` reference. See https://developers.cloudflare.com/workers/observability/errors/#illegal-invocation-errors for details.");
|
|
30
|
+
const a = source(left, 1), b = source(right, 2);
|
|
31
|
+
if (a.byteLength !== b.byteLength)
|
|
32
|
+
throw new TypeError("Input buffers must have the same byte length.");
|
|
33
|
+
return nativeTimingEqual(a, b);
|
|
34
|
+
}
|
|
35
|
+
// Preserve host Crypto/SubtleCrypto identity. Digest uses the Workers registry;
|
|
36
|
+
// other standard operations retain their host implementation.
|
|
37
|
+
// These Workers extensions use the owned digest and comparison backend.
|
|
38
|
+
if (!("DigestStream" in webcrypto))
|
|
39
|
+
Object.defineProperty(Object.getPrototypeOf(webcrypto), "DigestStream", {
|
|
40
|
+
value: DigestStream,
|
|
41
|
+
writable: true,
|
|
42
|
+
enumerable: true,
|
|
43
|
+
configurable: true,
|
|
44
|
+
});
|
|
45
|
+
if (!("timingSafeEqual" in subtle))
|
|
46
|
+
Object.defineProperty(Object.getPrototypeOf(subtle), "timingSafeEqual", {
|
|
47
|
+
value: timingSafeEqual,
|
|
48
|
+
writable: true,
|
|
49
|
+
enumerable: true,
|
|
50
|
+
configurable: true,
|
|
51
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { NativeX509 } from "./native-crypto.js";
|
|
2
|
+
import { PublicKeyObject, PrivateKeyObject } from "./keys.js";
|
|
3
|
+
export declare class X509Certificate {
|
|
4
|
+
#private;
|
|
5
|
+
constructor(buffer: ArrayBufferView | ArrayBuffer | NativeX509 | string);
|
|
6
|
+
get subject(): any;
|
|
7
|
+
get subjectAltName(): any;
|
|
8
|
+
get issuer(): any;
|
|
9
|
+
get issuerCertificate(): any;
|
|
10
|
+
get infoAccess(): any;
|
|
11
|
+
get validFrom(): any;
|
|
12
|
+
get validTo(): any;
|
|
13
|
+
get fingerprint(): any;
|
|
14
|
+
get fingerprint256(): any;
|
|
15
|
+
get fingerprint512(): any;
|
|
16
|
+
get keyUsage(): any;
|
|
17
|
+
get serialNumber(): any;
|
|
18
|
+
get raw(): any;
|
|
19
|
+
get publicKey(): any;
|
|
20
|
+
toString(): any;
|
|
21
|
+
toJSON(): any;
|
|
22
|
+
get ca(): any;
|
|
23
|
+
checkHost(name: string, options?: any): string | undefined;
|
|
24
|
+
checkEmail(email: string, options?: any): string | undefined;
|
|
25
|
+
checkIP(ip: string, options?: any): string | undefined;
|
|
26
|
+
checkIssued(otherCert: X509Certificate): boolean;
|
|
27
|
+
checkPrivateKey(pkey: PrivateKeyObject): boolean;
|
|
28
|
+
verify(pkey: PublicKeyObject): boolean;
|
|
29
|
+
toLegacyObject(): any;
|
|
30
|
+
}
|
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
// Copyright (c) 2017-2022 Cloudflare, Inc.
|
|
2
|
+
// Licensed under the Apache 2.0 license found in the LICENSE file or at:
|
|
3
|
+
// https://opensource.org/licenses/Apache-2.0
|
|
4
|
+
//
|
|
5
|
+
// Copyright Joyent, Inc. and other Node contributors.
|
|
6
|
+
//
|
|
7
|
+
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
8
|
+
// copy of this software and associated documentation files (the
|
|
9
|
+
// "Software"), to deal in the Software without restriction, including
|
|
10
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
|
11
|
+
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
12
|
+
// persons to whom the Software is furnished to do so, subject to the
|
|
13
|
+
// following conditions:
|
|
14
|
+
//
|
|
15
|
+
// The above copyright notice and this permission notice shall be included
|
|
16
|
+
// in all copies or substantial portions of the Software.
|
|
17
|
+
//
|
|
18
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
19
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
20
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
21
|
+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
22
|
+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
23
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
24
|
+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
25
|
+
/* TODO: the following is adopted code, enabling linting one day */
|
|
26
|
+
/* eslint-disable */
|
|
27
|
+
import { viewBytes } from "../../shared/buffer-source.js";
|
|
28
|
+
import { NativeX509 } from "./native-crypto.js";
|
|
29
|
+
import { validateString, validateObject, validateBoolean, } from "../net/validators.js";
|
|
30
|
+
import { Buffer } from "buffer";
|
|
31
|
+
import { ERR_INVALID_ARG_TYPE, ERR_INVALID_ARG_VALUE } from "../net/errors.js";
|
|
32
|
+
import { PublicKeyObject, PrivateKeyObject, create } from "./keys.js";
|
|
33
|
+
import { keyStates } from "./key-state.js";
|
|
34
|
+
const isArrayBufferView = ArrayBuffer.isView;
|
|
35
|
+
const certificateKeys = new WeakSet();
|
|
36
|
+
function flags(options) {
|
|
37
|
+
// BoringSSL always forbids partial-label wildcards. The ALWAYS_CHECK_SUBJECT,
|
|
38
|
+
// MULTI_LABEL_WILDCARDS and SINGLE_LABEL_SUBDOMAINS flags are zero there.
|
|
39
|
+
// https://boringssl.googlesource.com/boringssl/+/refs/heads/fips-20240407/include/openssl/x509.h
|
|
40
|
+
let flags = 4;
|
|
41
|
+
if (options == null)
|
|
42
|
+
return flags;
|
|
43
|
+
if (options.wildcards === false)
|
|
44
|
+
flags |= 2;
|
|
45
|
+
if (options.subject === "never")
|
|
46
|
+
flags |= 32;
|
|
47
|
+
else if (options.subject !== undefined &&
|
|
48
|
+
options.subject !== "default" &&
|
|
49
|
+
options.subject !== "always")
|
|
50
|
+
throw new Error("Invalid subject option");
|
|
51
|
+
return flags;
|
|
52
|
+
}
|
|
53
|
+
function translatePeerCertificate(c) {
|
|
54
|
+
if (!c)
|
|
55
|
+
return null;
|
|
56
|
+
if (c.issuerCertificate != null && c.issuerCertificate !== c) {
|
|
57
|
+
c.issuerCertificate = translatePeerCertificate(c.issuerCertificate);
|
|
58
|
+
}
|
|
59
|
+
if (c.infoAccess != null) {
|
|
60
|
+
const info = c.infoAccess;
|
|
61
|
+
c.infoAccess = {};
|
|
62
|
+
// XXX: More key validation?
|
|
63
|
+
const regex = /([^\n:]*):([^\n]*)(?:\n|$)/g;
|
|
64
|
+
regex[Symbol.replace](info, (_, key, val) => {
|
|
65
|
+
if (val.charCodeAt(0) === 0x22) {
|
|
66
|
+
// The translatePeerCertificate function is only
|
|
67
|
+
// used on internally created legacy certificate
|
|
68
|
+
// objects, and any value that contains a quote
|
|
69
|
+
// will always be a valid JSON string literal,
|
|
70
|
+
// so this should never throw.
|
|
71
|
+
val = JSON.parse(val);
|
|
72
|
+
}
|
|
73
|
+
if (key in c.infoAccess)
|
|
74
|
+
c.infoAccess[key].push(val);
|
|
75
|
+
else
|
|
76
|
+
c.infoAccess[key] = [val];
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return c;
|
|
80
|
+
}
|
|
81
|
+
function checkOptions(options) {
|
|
82
|
+
if (options == null)
|
|
83
|
+
return;
|
|
84
|
+
validateObject(options, "options");
|
|
85
|
+
if (options.multiLabelWildcards !== undefined)
|
|
86
|
+
validateBoolean(options.multiLabelWildcards, "options.multiLabelWildcards");
|
|
87
|
+
if (options.partialWildcards !== undefined)
|
|
88
|
+
validateBoolean(options.partialWildcards, "options.partialWildcards");
|
|
89
|
+
if (options.singleLabelSubdomains !== undefined)
|
|
90
|
+
validateBoolean(options.singleLabelSubdomains, "options.singleLabelSubdomains");
|
|
91
|
+
if (options.wildcards !== undefined)
|
|
92
|
+
validateBoolean(options.wildcards, "options.wildcards");
|
|
93
|
+
if (options.subject !== undefined)
|
|
94
|
+
validateString(options.subject, "options.subject");
|
|
95
|
+
}
|
|
96
|
+
export class X509Certificate {
|
|
97
|
+
#handle;
|
|
98
|
+
#state = new Map();
|
|
99
|
+
constructor(buffer) {
|
|
100
|
+
if (buffer instanceof NativeX509) {
|
|
101
|
+
this.#handle = buffer;
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (typeof buffer === "string") {
|
|
105
|
+
buffer = Buffer.from(buffer);
|
|
106
|
+
}
|
|
107
|
+
if (!isArrayBufferView(buffer)) {
|
|
108
|
+
throw new ERR_INVALID_ARG_TYPE("buffer", ["string", "Buffer", "TypedArray", "DataView"], buffer);
|
|
109
|
+
}
|
|
110
|
+
const handle = NativeX509.parse(viewBytes(buffer));
|
|
111
|
+
if (handle == null) {
|
|
112
|
+
throw new ERR_INVALID_ARG_VALUE("buffer", buffer, "is not a valid certificate");
|
|
113
|
+
}
|
|
114
|
+
this.#handle = handle;
|
|
115
|
+
}
|
|
116
|
+
get subject() {
|
|
117
|
+
let value = this.#state.get("subject");
|
|
118
|
+
if (value === undefined) {
|
|
119
|
+
value = this.#handle.string(0);
|
|
120
|
+
this.#state.set("subject", value);
|
|
121
|
+
}
|
|
122
|
+
return value ?? undefined;
|
|
123
|
+
}
|
|
124
|
+
get subjectAltName() {
|
|
125
|
+
let value = this.#state.get("subjectAltName");
|
|
126
|
+
if (value === undefined) {
|
|
127
|
+
value = this.#handle.string(2);
|
|
128
|
+
this.#state.set("subjectAltName", value);
|
|
129
|
+
}
|
|
130
|
+
return value ?? undefined;
|
|
131
|
+
}
|
|
132
|
+
get issuer() {
|
|
133
|
+
let value = this.#state.get("issuer");
|
|
134
|
+
if (value === undefined) {
|
|
135
|
+
value = this.#handle.string(1);
|
|
136
|
+
this.#state.set("issuer", value);
|
|
137
|
+
}
|
|
138
|
+
return value ?? undefined;
|
|
139
|
+
}
|
|
140
|
+
get issuerCertificate() {
|
|
141
|
+
let value = this.#state.get("issuerCertificate");
|
|
142
|
+
if (value === undefined) {
|
|
143
|
+
this.#state.set("issuerCertificate", value);
|
|
144
|
+
}
|
|
145
|
+
return value ?? undefined;
|
|
146
|
+
}
|
|
147
|
+
get infoAccess() {
|
|
148
|
+
let value = this.#state.get("infoAccess");
|
|
149
|
+
if (value === undefined) {
|
|
150
|
+
value = this.#handle.string(3);
|
|
151
|
+
this.#state.set("infoAccess", value);
|
|
152
|
+
}
|
|
153
|
+
return value ?? undefined;
|
|
154
|
+
}
|
|
155
|
+
get validFrom() {
|
|
156
|
+
let value = this.#state.get("validFrom");
|
|
157
|
+
if (value === undefined) {
|
|
158
|
+
value = this.#handle.string(4);
|
|
159
|
+
this.#state.set("validFrom", value);
|
|
160
|
+
}
|
|
161
|
+
return value ?? undefined;
|
|
162
|
+
}
|
|
163
|
+
get validTo() {
|
|
164
|
+
let value = this.#state.get("validTo");
|
|
165
|
+
if (value === undefined) {
|
|
166
|
+
value = this.#handle.string(5);
|
|
167
|
+
this.#state.set("validTo", value);
|
|
168
|
+
}
|
|
169
|
+
return value ?? undefined;
|
|
170
|
+
}
|
|
171
|
+
get fingerprint() {
|
|
172
|
+
let value = this.#state.get("fingerprint");
|
|
173
|
+
if (value === undefined) {
|
|
174
|
+
value = this.#handle.string(6);
|
|
175
|
+
this.#state.set("fingerprint", value);
|
|
176
|
+
}
|
|
177
|
+
return value ?? undefined;
|
|
178
|
+
}
|
|
179
|
+
get fingerprint256() {
|
|
180
|
+
let value = this.#state.get("fingerprint256");
|
|
181
|
+
if (value === undefined) {
|
|
182
|
+
value = this.#handle.string(7);
|
|
183
|
+
this.#state.set("fingerprint256", value);
|
|
184
|
+
}
|
|
185
|
+
return value ?? undefined;
|
|
186
|
+
}
|
|
187
|
+
get fingerprint512() {
|
|
188
|
+
let value = this.#state.get("fingerprint512");
|
|
189
|
+
if (value === undefined) {
|
|
190
|
+
value = this.#handle.string(8);
|
|
191
|
+
this.#state.set("fingerprint512", value);
|
|
192
|
+
}
|
|
193
|
+
return value ?? undefined;
|
|
194
|
+
}
|
|
195
|
+
get keyUsage() {
|
|
196
|
+
let value = this.#state.get("keyUsage");
|
|
197
|
+
if (value === undefined) {
|
|
198
|
+
value = this.#handle.string(12)?.split("\n");
|
|
199
|
+
this.#state.set("keyUsage", value);
|
|
200
|
+
}
|
|
201
|
+
return value ?? undefined;
|
|
202
|
+
}
|
|
203
|
+
get serialNumber() {
|
|
204
|
+
let value = this.#state.get("serialNumber");
|
|
205
|
+
if (value === undefined) {
|
|
206
|
+
value = this.#handle.string(9);
|
|
207
|
+
if (value != null)
|
|
208
|
+
value = value.toUpperCase();
|
|
209
|
+
this.#state.set("serialNumber", value);
|
|
210
|
+
}
|
|
211
|
+
return value ?? undefined;
|
|
212
|
+
}
|
|
213
|
+
get raw() {
|
|
214
|
+
let value = this.#state.get("raw");
|
|
215
|
+
if (value === undefined) {
|
|
216
|
+
value = this.#handle.field(10);
|
|
217
|
+
if (value != null)
|
|
218
|
+
value = Buffer.from(value);
|
|
219
|
+
this.#state.set("raw", value);
|
|
220
|
+
}
|
|
221
|
+
return value ?? undefined;
|
|
222
|
+
}
|
|
223
|
+
get publicKey() {
|
|
224
|
+
let value = this.#state.get("publicKey");
|
|
225
|
+
if (value === undefined) {
|
|
226
|
+
const inner = this.#handle.publicKey;
|
|
227
|
+
if (inner !== undefined) {
|
|
228
|
+
value = create("public", { asymmetric: inner });
|
|
229
|
+
certificateKeys.add(value);
|
|
230
|
+
this.#state.set("publicKey", value);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return value ?? undefined;
|
|
234
|
+
}
|
|
235
|
+
toString() {
|
|
236
|
+
let value = this.#state.get("pem");
|
|
237
|
+
if (value === undefined) {
|
|
238
|
+
value = this.#handle.string(11);
|
|
239
|
+
this.#state.set("pem", value);
|
|
240
|
+
}
|
|
241
|
+
return value ?? undefined;
|
|
242
|
+
}
|
|
243
|
+
// There's no standardized JSON encoding for X509 certs so we
|
|
244
|
+
// fallback to providing the PEM encoding as a string.
|
|
245
|
+
toJSON() {
|
|
246
|
+
return this.toString();
|
|
247
|
+
}
|
|
248
|
+
get ca() {
|
|
249
|
+
let value = this.#state.get("ca");
|
|
250
|
+
if (value === undefined) {
|
|
251
|
+
value = this.#handle.isCA;
|
|
252
|
+
this.#state.set("ca", value);
|
|
253
|
+
}
|
|
254
|
+
return value ?? false;
|
|
255
|
+
}
|
|
256
|
+
checkHost(name, options) {
|
|
257
|
+
validateString(name, "name");
|
|
258
|
+
checkOptions(options);
|
|
259
|
+
return this.#handle.check(name, flags(options), 0) ?? undefined;
|
|
260
|
+
}
|
|
261
|
+
checkEmail(email, options) {
|
|
262
|
+
validateString(email, "email");
|
|
263
|
+
checkOptions(options);
|
|
264
|
+
return this.#handle.check(email, flags(options), 1) ?? undefined;
|
|
265
|
+
}
|
|
266
|
+
checkIP(ip, options) {
|
|
267
|
+
validateString(ip, "ip");
|
|
268
|
+
checkOptions(options);
|
|
269
|
+
// The options argument is currently undocumented since none of the options
|
|
270
|
+
// have any effect on the behavior of this function. However, we still parse
|
|
271
|
+
// the options argument in case OpenSSL adds flags in the future that do
|
|
272
|
+
// affect the behavior of X509_check_ip. This ensures that no invalid values
|
|
273
|
+
// are passed as the second argument in the meantime.
|
|
274
|
+
return this.#handle.check(ip, flags(options), 2) ?? undefined;
|
|
275
|
+
}
|
|
276
|
+
checkIssued(otherCert) {
|
|
277
|
+
if (!(otherCert instanceof X509Certificate))
|
|
278
|
+
throw new ERR_INVALID_ARG_TYPE("otherCert", "X509Certificate", otherCert);
|
|
279
|
+
return this.#handle.checkIssued(otherCert.#handle) ?? undefined;
|
|
280
|
+
}
|
|
281
|
+
checkPrivateKey(pkey) {
|
|
282
|
+
if (!(pkey instanceof PrivateKeyObject))
|
|
283
|
+
throw new ERR_INVALID_ARG_TYPE("pkey", "KeyObject", pkey);
|
|
284
|
+
if (pkey.type !== "private")
|
|
285
|
+
throw new ERR_INVALID_ARG_VALUE("pkey", pkey);
|
|
286
|
+
// Pinned workerd returns false for imported/generated private KeyObjects,
|
|
287
|
+
// even when their public material matches (RSA and EC comparison fixtures).
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
verify(pkey) {
|
|
291
|
+
if (!(pkey instanceof PublicKeyObject))
|
|
292
|
+
throw new ERR_INVALID_ARG_TYPE("pkey", "KeyObject", pkey);
|
|
293
|
+
if (pkey.type !== "public")
|
|
294
|
+
throw new ERR_INVALID_ARG_VALUE("pkey", pkey);
|
|
295
|
+
// Keys exposed by X509 retain the certificate backend in the pinned runtime.
|
|
296
|
+
return (certificateKeys.has(pkey) &&
|
|
297
|
+
this.#handle.checkKey(keyStates.get(pkey).asymmetric, 2));
|
|
298
|
+
}
|
|
299
|
+
#legacy() {
|
|
300
|
+
const name = (field) => {
|
|
301
|
+
const data = this.#handle.field(field) ?? new Uint8Array();
|
|
302
|
+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
303
|
+
const decoder = new TextDecoder();
|
|
304
|
+
let offset = 0;
|
|
305
|
+
const next = () => {
|
|
306
|
+
const size = view.getUint32(offset);
|
|
307
|
+
offset += 4;
|
|
308
|
+
const value = decoder.decode(data.subarray(offset, offset + size));
|
|
309
|
+
offset += size;
|
|
310
|
+
return value;
|
|
311
|
+
};
|
|
312
|
+
const out = {};
|
|
313
|
+
while (offset < data.byteLength) {
|
|
314
|
+
const key = next(), value = next();
|
|
315
|
+
if (Object.hasOwn(out, key)) {
|
|
316
|
+
const old = out[key];
|
|
317
|
+
out[key] = Array.isArray(old) ? [...old, value] : [old, value];
|
|
318
|
+
}
|
|
319
|
+
else
|
|
320
|
+
Object.defineProperty(out, key, {
|
|
321
|
+
value,
|
|
322
|
+
writable: true,
|
|
323
|
+
enumerable: true,
|
|
324
|
+
configurable: true,
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
return out;
|
|
328
|
+
};
|
|
329
|
+
const key = keyStates.get(this.publicKey)?.asymmetric;
|
|
330
|
+
const out = {
|
|
331
|
+
subject: name(13),
|
|
332
|
+
issuer: name(14),
|
|
333
|
+
subjectAltName: this.subjectAltName ?? "",
|
|
334
|
+
infoAccess: this.infoAccess ?? "",
|
|
335
|
+
ca: this.ca,
|
|
336
|
+
valid_from: this.validFrom,
|
|
337
|
+
valid_to: this.validTo,
|
|
338
|
+
fingerprint: this.fingerprint,
|
|
339
|
+
fingerprint256: this.fingerprint256,
|
|
340
|
+
fingerprint512: this.fingerprint512,
|
|
341
|
+
serialNumber: this.serialNumber,
|
|
342
|
+
ext_key_usage: this.keyUsage,
|
|
343
|
+
raw: this.raw,
|
|
344
|
+
};
|
|
345
|
+
if (key?.type === "rsa") {
|
|
346
|
+
out.bits = key.bits;
|
|
347
|
+
out.modulus = Buffer.from(key.parameter("n"))
|
|
348
|
+
.toString("hex")
|
|
349
|
+
.replace(/^0+/, "")
|
|
350
|
+
.toUpperCase();
|
|
351
|
+
out.exponent =
|
|
352
|
+
"0x" +
|
|
353
|
+
BigInt("0x" + Buffer.from(key.parameter("e")).toString("hex")).toString(16);
|
|
354
|
+
out.pubkey = key.export(false, false, "spki");
|
|
355
|
+
}
|
|
356
|
+
else if (key?.type === "ec") {
|
|
357
|
+
out.bits = key.bits;
|
|
358
|
+
out.pubkey = this.#handle.field(17);
|
|
359
|
+
out.asn1Curve = this.#handle.string(15);
|
|
360
|
+
out.nistCurve = this.#handle.string(16);
|
|
361
|
+
}
|
|
362
|
+
return out;
|
|
363
|
+
}
|
|
364
|
+
toLegacyObject() {
|
|
365
|
+
let value = this.#state.get("legacy");
|
|
366
|
+
if (value === undefined) {
|
|
367
|
+
let { subject, subjectAltName, infoAccess, issuer, ca, modulus, bits, exponent, pubkey, asn1Curve, nistCurve, valid_from, valid_to, fingerprint, fingerprint256, fingerprint512, serialNumber, ext_key_usage, raw, } = this.#legacy();
|
|
368
|
+
if (raw != null)
|
|
369
|
+
raw = Buffer.from(raw);
|
|
370
|
+
if (pubkey != null)
|
|
371
|
+
pubkey = Buffer.from(pubkey);
|
|
372
|
+
if (modulus != null)
|
|
373
|
+
modulus = modulus.toUpperCase();
|
|
374
|
+
if (fingerprint != null)
|
|
375
|
+
fingerprint = fingerprint.toUpperCase();
|
|
376
|
+
if (fingerprint256 != null)
|
|
377
|
+
fingerprint256 = fingerprint256.toUpperCase();
|
|
378
|
+
if (fingerprint512 != null)
|
|
379
|
+
fingerprint512 = fingerprint512.toUpperCase();
|
|
380
|
+
if (serialNumber != null)
|
|
381
|
+
serialNumber = serialNumber.toUpperCase();
|
|
382
|
+
value = translatePeerCertificate({
|
|
383
|
+
subject,
|
|
384
|
+
subjectAltName,
|
|
385
|
+
infoAccess,
|
|
386
|
+
issuer,
|
|
387
|
+
ca,
|
|
388
|
+
modulus,
|
|
389
|
+
bits,
|
|
390
|
+
exponent,
|
|
391
|
+
pubkey,
|
|
392
|
+
asn1Curve,
|
|
393
|
+
nistCurve,
|
|
394
|
+
valid_from,
|
|
395
|
+
valid_to,
|
|
396
|
+
fingerprint,
|
|
397
|
+
fingerprint256,
|
|
398
|
+
fingerprint512,
|
|
399
|
+
serialNumber,
|
|
400
|
+
ext_key_usage,
|
|
401
|
+
raw,
|
|
402
|
+
});
|
|
403
|
+
this.#state.set("legacy", value);
|
|
404
|
+
}
|
|
405
|
+
return value;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { AbortError, ERR_INVALID_ARG_TYPE, ERR_OUT_OF_RANGE, } from "../net/errors.js";
|
|
2
|
+
import { NodeError, NodeTypeError } from "../net/error-base.js";
|
|
3
|
+
export declare class ERR_UNHANDLED_ERROR extends NodeError {
|
|
4
|
+
constructor(x: string);
|
|
5
|
+
}
|
|
6
|
+
export declare class ERR_INVALID_THIS extends NodeTypeError {
|
|
7
|
+
constructor(x: string);
|
|
8
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Copyright (c) 2017-2022 Cloudflare, Inc.
|
|
2
|
+
// Licensed under the Apache 2.0 license found in the LICENSE file or at:
|
|
3
|
+
// https://opensource.org/licenses/Apache-2.0
|
|
4
|
+
//
|
|
5
|
+
// Adapted from Deno and Node.js:
|
|
6
|
+
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
|
7
|
+
//
|
|
8
|
+
// Adapted from Node.js. Copyright Joyent, Inc. and other Node contributors.
|
|
9
|
+
//
|
|
10
|
+
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
11
|
+
// copy of this software and associated documentation files (the
|
|
12
|
+
// "Software"), to deal in the Software without restriction, including
|
|
13
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
|
14
|
+
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
15
|
+
// persons to whom the Software is furnished to do so, subject to the
|
|
16
|
+
// following conditions:
|
|
17
|
+
//
|
|
18
|
+
// The above copyright notice and this permission notice shall be included
|
|
19
|
+
// in all copies or substantial portions of the Software.
|
|
20
|
+
//
|
|
21
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
22
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
23
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
24
|
+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
25
|
+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
26
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
27
|
+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
28
|
+
export { AbortError, ERR_INVALID_ARG_TYPE, ERR_OUT_OF_RANGE, } from "../net/errors.js";
|
|
29
|
+
import { NodeError, NodeTypeError } from "../net/error-base.js";
|
|
30
|
+
export class ERR_UNHANDLED_ERROR extends NodeError {
|
|
31
|
+
constructor(x) {
|
|
32
|
+
super("ERR_UNHANDLED_ERROR", `Unhandled error. (${x})`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export class ERR_INVALID_THIS extends NodeTypeError {
|
|
36
|
+
constructor(x) {
|
|
37
|
+
super("ERR_INVALID_THIS", `Value of "this" must be of type ${x}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { EventEmitterAsyncResource as _EventEmitterAsyncResource, EventEmitter as _EventEmitter } from "node:events";
|
|
2
|
+
import { default as async_hooks } from "node:async_hooks";
|
|
3
|
+
declare const AsyncResource: typeof async_hooks.AsyncResource;
|
|
4
|
+
declare const kRejection: unique symbol;
|
|
5
|
+
declare const kErrorMonitor: unique symbol;
|
|
6
|
+
export interface EventEmitterOptions {
|
|
7
|
+
captureRejections?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export type EventName = string | symbol | number;
|
|
10
|
+
export type EventCallback = ((...args: any[]) => unknown) & {
|
|
11
|
+
listener?: EventCallback;
|
|
12
|
+
};
|
|
13
|
+
interface EventEmitter extends _EventEmitter {
|
|
14
|
+
_events: Record<string | symbol, any> | undefined;
|
|
15
|
+
_eventsCount: number;
|
|
16
|
+
}
|
|
17
|
+
type AsyncResource = typeof AsyncResource;
|
|
18
|
+
export declare function EventEmitter(this: EventEmitter, opts?: EventEmitterOptions): EventEmitter;
|
|
19
|
+
export declare namespace EventEmitter {
|
|
20
|
+
export { on };
|
|
21
|
+
export { once };
|
|
22
|
+
export { getEventListeners };
|
|
23
|
+
export { _getMaxListeners as getMaxListeners };
|
|
24
|
+
export { setMaxListeners };
|
|
25
|
+
export { listenerCount };
|
|
26
|
+
export { EventEmitter };
|
|
27
|
+
export var _a: boolean;
|
|
28
|
+
export { _a as usingDomains };
|
|
29
|
+
export { kRejection as captureRejectionSymbol };
|
|
30
|
+
export { kErrorMonitor as errorMonitor };
|
|
31
|
+
export { EventEmitterAsyncResource };
|
|
32
|
+
export var init: (this: EventEmitter, opts?: EventEmitterOptions) => void;
|
|
33
|
+
export { addAbortListener };
|
|
34
|
+
}
|
|
35
|
+
declare const EventEmitterConstructor: typeof _EventEmitter;
|
|
36
|
+
export declare class EventEmitterAsyncResource extends EventEmitterConstructor implements _EventEmitterAsyncResource {
|
|
37
|
+
#private;
|
|
38
|
+
constructor(options?: EventEmitterOptions);
|
|
39
|
+
get asyncResource(): AsyncResource;
|
|
40
|
+
emit(event: string | symbol, ...args: any[]): boolean;
|
|
41
|
+
}
|
|
42
|
+
export declare function addAbortListener(signal: AbortSignal | undefined, listener: any): {
|
|
43
|
+
__proto__: null;
|
|
44
|
+
[Symbol.dispose](): void;
|
|
45
|
+
};
|
|
46
|
+
export default EventEmitter;
|
|
47
|
+
export declare const captureRejectionSymbol: symbol;
|
|
48
|
+
export declare const captureRejections = false;
|
|
49
|
+
export declare const errorMonitor: symbol;
|
|
50
|
+
export declare const getMaxListeners: typeof _getMaxListeners;
|
|
51
|
+
export declare const usingDomains = false;
|
|
52
|
+
export declare let defaultMaxListeners: number;
|
|
53
|
+
export declare function setMaxListeners(n?: number, ...eventTargets: any[]): void;
|
|
54
|
+
declare function _getMaxListeners(that: any): any;
|
|
55
|
+
export declare function listenerCount(emitter: any, type: string | symbol): any;
|
|
56
|
+
export declare function getEventListeners(emitterOrTarget: any, type: string | symbol): any;
|
|
57
|
+
export interface OnceOptions {
|
|
58
|
+
signal?: AbortSignal;
|
|
59
|
+
}
|
|
60
|
+
export declare function once(emitter: any, name: string | symbol, options?: OnceOptions): Promise<unknown>;
|
|
61
|
+
interface OnOptions {
|
|
62
|
+
signal?: AbortSignal;
|
|
63
|
+
}
|
|
64
|
+
export declare function on(emitter: any, event: string | symbol, options?: OnOptions): any;
|