@browsercore/tls 0.1.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/LICENSE +21 -0
- package/README.md +65 -0
- package/dist/certificates/certificates.d.ts +78 -0
- package/dist/certificates/certificates.d.ts.map +1 -0
- package/dist/certificates/certificates.js +692 -0
- package/dist/certificates/certificates.js.map +1 -0
- package/dist/crypto/keySchedule.d.ts +65 -0
- package/dist/crypto/keySchedule.d.ts.map +1 -0
- package/dist/crypto/keySchedule.js +197 -0
- package/dist/crypto/keySchedule.js.map +1 -0
- package/dist/errors.d.ts +53 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +72 -0
- package/dist/errors.js.map +1 -0
- package/dist/extensions/extensions.d.ts +89 -0
- package/dist/extensions/extensions.d.ts.map +1 -0
- package/dist/extensions/extensions.js +141 -0
- package/dist/extensions/extensions.js.map +1 -0
- package/dist/handshake/handshake.d.ts +98 -0
- package/dist/handshake/handshake.d.ts.map +1 -0
- package/dist/handshake/handshake.js +366 -0
- package/dist/handshake/handshake.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/profiles/profiles.d.ts +28 -0
- package/dist/profiles/profiles.d.ts.map +1 -0
- package/dist/profiles/profiles.js +68 -0
- package/dist/profiles/profiles.js.map +1 -0
- package/dist/record/record.d.ts +80 -0
- package/dist/record/record.d.ts.map +1 -0
- package/dist/record/record.js +135 -0
- package/dist/record/record.js.map +1 -0
- package/dist/tls.d.ts +56 -0
- package/dist/tls.d.ts.map +1 -0
- package/dist/tls.js +102 -0
- package/dist/tls.js.map +1 -0
- package/dist/types.d.ts +157 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +12 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +15 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +20 -0
- package/dist/utils.js.map +1 -0
- package/package.json +51 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Domain types for @browsercore/tls.
|
|
3
|
+
*
|
|
4
|
+
* This package owns TLS 1.3 (and 1.2 fallback) protocol logic. It knows about
|
|
5
|
+
* byte streams (@browsercore/transport) and cryptographic primitives (@browsercore/crypto)
|
|
6
|
+
* but NEVER imports node:crypto directly — that boundary is @browsercore/crypto's job.
|
|
7
|
+
*/
|
|
8
|
+
import type { Transport } from "@browsercore/transport";
|
|
9
|
+
import type { TlsError } from "./errors.js";
|
|
10
|
+
/** Branded TLS session identifier. */
|
|
11
|
+
export type TlsSessionId = string & {
|
|
12
|
+
__brand: "TlsSessionId";
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* TLS protocol versions. Wire values follow RFC 8446 / RFC 5246:
|
|
16
|
+
* TLS 1.2 = 0x0303, TLS 1.3 = 0x0304.
|
|
17
|
+
*/
|
|
18
|
+
export type ProtocolVersion = {
|
|
19
|
+
readonly name: "TLS 1.2";
|
|
20
|
+
readonly wire: 0x0303;
|
|
21
|
+
} | {
|
|
22
|
+
readonly name: "TLS 1.3";
|
|
23
|
+
readonly wire: 0x0304;
|
|
24
|
+
};
|
|
25
|
+
/** TLS 1.2 protocol version constant. */
|
|
26
|
+
export declare const TLS_1_2: ProtocolVersion;
|
|
27
|
+
/** TLS 1.3 protocol version constant. */
|
|
28
|
+
export declare const TLS_1_3: ProtocolVersion;
|
|
29
|
+
/** AEAD algorithms used by TLS record protection. */
|
|
30
|
+
export type AeadAlgorithm = "AES-128-GCM" | "AES-256-GCM" | "CHACHA20-POLY1305";
|
|
31
|
+
/** A TLS 1.3 cipher suite (AEAD + hash). String-literal union — never bare string. */
|
|
32
|
+
export type CipherSuite = "TLS_AES_128_GCM_SHA256" | "TLS_AES_256_GCM_SHA384" | "TLS_CHACHA20_POLY1305_SHA256" | "TLS_AES_128_CCM_SHA256";
|
|
33
|
+
/** Named groups for key share (ECDHE). */
|
|
34
|
+
export type NamedGroup = "secp256r1" | "secp384r1" | "x25519" | "x448";
|
|
35
|
+
/** Signature algorithms for certificate verification. */
|
|
36
|
+
export type SignatureScheme = "ecdsa_secp256r1_sha256" | "ecdsa_secp384r1_sha384" | "rsa_pss_rsae_sha256" | "rsa_pss_rsae_sha384" | "rsa_pkcs1_sha256";
|
|
37
|
+
/** Why a TLS connection was closed. Discriminated union — every case is explicit. */
|
|
38
|
+
export type CloseReason = {
|
|
39
|
+
readonly kind: "close_notify";
|
|
40
|
+
readonly alert?: number;
|
|
41
|
+
} | {
|
|
42
|
+
readonly kind: "error";
|
|
43
|
+
readonly error: TlsError;
|
|
44
|
+
} | {
|
|
45
|
+
readonly kind: "transport_closed";
|
|
46
|
+
} | {
|
|
47
|
+
readonly kind: "timeout";
|
|
48
|
+
readonly afterMs: number;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Lifecycle state of a TLS connection.
|
|
52
|
+
*
|
|
53
|
+
* `open` carries the negotiated parameters so they can be observed without
|
|
54
|
+
* re-deriving them. `closed` carries the reason for observability.
|
|
55
|
+
*/
|
|
56
|
+
export type TlsState = {
|
|
57
|
+
readonly state: "connecting";
|
|
58
|
+
} | {
|
|
59
|
+
readonly state: "handshaking";
|
|
60
|
+
} | {
|
|
61
|
+
readonly state: "open";
|
|
62
|
+
readonly sessionId: TlsSessionId;
|
|
63
|
+
readonly protocolVersion: ProtocolVersion;
|
|
64
|
+
readonly cipherSuite: CipherSuite;
|
|
65
|
+
readonly alpnProtocol?: string;
|
|
66
|
+
} | {
|
|
67
|
+
readonly state: "closed";
|
|
68
|
+
readonly reason: CloseReason;
|
|
69
|
+
};
|
|
70
|
+
/** Configuration for building a ClientHello. Placeholder until @browsercore/profiles. */
|
|
71
|
+
export interface ClientHelloConfig {
|
|
72
|
+
/** Ordered list of cipher suites the client advertises (most-preferred first). */
|
|
73
|
+
readonly cipherSuites: readonly CipherSuite[];
|
|
74
|
+
/** Named groups for key share, ordered by preference. */
|
|
75
|
+
readonly keyShareGroups: readonly NamedGroup[];
|
|
76
|
+
/** Signature algorithms the client accepts in CertificateVerify. */
|
|
77
|
+
readonly signatureAlgorithms: readonly SignatureScheme[];
|
|
78
|
+
/** Protocol versions the client advertises via supported_versions. */
|
|
79
|
+
readonly supportedVersions: readonly ProtocolVersion[];
|
|
80
|
+
/** Server Name Indication hostname (SNI). */
|
|
81
|
+
readonly serverName: string;
|
|
82
|
+
/** ALPN protocols the client wishes to negotiate (e.g. "h2", "http/1.1"). */
|
|
83
|
+
readonly alpnProtocols?: readonly string[];
|
|
84
|
+
}
|
|
85
|
+
/** Public options for {@link connectTls}. */
|
|
86
|
+
export interface TlsOptions {
|
|
87
|
+
/** The underlying byte-stream transport (already connected or connecting). */
|
|
88
|
+
readonly transport: Transport;
|
|
89
|
+
/** SNI server name. Defaults to host if omitted. */
|
|
90
|
+
readonly serverName: string;
|
|
91
|
+
/** ClientHello configuration (placeholder until @browsercore/profiles is built). */
|
|
92
|
+
readonly profile: ClientHelloConfig;
|
|
93
|
+
/** ALPN protocols to offer. Overrides profile.alpnProtocols if provided. */
|
|
94
|
+
readonly alpnProtocols?: readonly string[];
|
|
95
|
+
/** Connect + handshake timeout in milliseconds. Default 10_000. */
|
|
96
|
+
readonly handshakeTimeoutMs?: number;
|
|
97
|
+
/** Trust anchors (PEM or DER) for certificate verification. Defaults to system roots. */
|
|
98
|
+
readonly trustAnchors?: readonly Uint8Array[];
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* An asymmetric key pair. Bytes are algorithm-specific; this package never
|
|
102
|
+
* generates them — it asks @browsercore/crypto.
|
|
103
|
+
*/
|
|
104
|
+
export interface KeyPair {
|
|
105
|
+
readonly algorithm: "x25519" | "secp256r1" | "secp384r1";
|
|
106
|
+
/** Private key bytes (opaque to this package). */
|
|
107
|
+
readonly privateKey: Uint8Array;
|
|
108
|
+
/** Public key bytes, as would appear in a KeyShareEntry. */
|
|
109
|
+
readonly publicKey: Uint8Array;
|
|
110
|
+
}
|
|
111
|
+
/** Traffic secrets derived by the TLS 1.3 key schedule for one direction. */
|
|
112
|
+
export interface TrafficSecrets {
|
|
113
|
+
/** AEAD key for this direction. */
|
|
114
|
+
readonly key: Uint8Array;
|
|
115
|
+
/** AEAD IV (often called "write_iv") for this direction. */
|
|
116
|
+
readonly iv: Uint8Array;
|
|
117
|
+
}
|
|
118
|
+
/** Full set of traffic secrets for both directions after the handshake. */
|
|
119
|
+
export interface ApplicationTrafficSecrets {
|
|
120
|
+
readonly client: TrafficSecrets;
|
|
121
|
+
readonly server: TrafficSecrets;
|
|
122
|
+
}
|
|
123
|
+
/** Application-data payload, decrypted and ready for the higher layer. */
|
|
124
|
+
export interface ApplicationData {
|
|
125
|
+
readonly payload: Uint8Array;
|
|
126
|
+
}
|
|
127
|
+
/** The public interface for an established TLS connection. */
|
|
128
|
+
export interface TlsConnection {
|
|
129
|
+
/** Opaque session identifier for logging / correlation. */
|
|
130
|
+
readonly id: TlsSessionId;
|
|
131
|
+
/** Current lifecycle state. */
|
|
132
|
+
readonly state: TlsState;
|
|
133
|
+
/** Negotiated protocol version (available once open). */
|
|
134
|
+
readonly protocolVersion: ProtocolVersion;
|
|
135
|
+
/** Negotiated cipher suite (available once open). */
|
|
136
|
+
readonly cipherSuite: CipherSuite;
|
|
137
|
+
/** ALPN protocol the server selected, if any. */
|
|
138
|
+
readonly alpnProtocol?: string;
|
|
139
|
+
/**
|
|
140
|
+
* Read the next decrypted application-data record. Resolves with the payload,
|
|
141
|
+
* or rejects if the connection closes before a complete record arrives.
|
|
142
|
+
*/
|
|
143
|
+
read(): Promise<ApplicationData>;
|
|
144
|
+
/**
|
|
145
|
+
* Encrypt and write application data. Resolves when the record has been
|
|
146
|
+
* handed to the transport. Rejects if the connection is not open.
|
|
147
|
+
*/
|
|
148
|
+
write(data: Uint8Array): Promise<void>;
|
|
149
|
+
/**
|
|
150
|
+
* Send close_notify and close the underlying transport. Resolves once the
|
|
151
|
+
* connection reaches the `closed` terminal state. Idempotent.
|
|
152
|
+
*/
|
|
153
|
+
close(): Promise<void>;
|
|
154
|
+
/** Subscribe to lifecycle events (close / error) for observability. */
|
|
155
|
+
on(event: "close" | "error", listener: (arg: CloseReason | TlsError) => void): this;
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,sCAAsC;AACtC,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG;IAAE,OAAO,EAAE,cAAc,CAAA;CAAE,CAAC;AAEhE;;;GAGG;AACH,MAAM,MAAM,eAAe,GACrB;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACnD;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1D,yCAAyC;AACzC,eAAO,MAAM,OAAO,EAAE,eAA4D,CAAC;AAEnF,yCAAyC;AACzC,eAAO,MAAM,OAAO,EAAE,eAA4D,CAAC;AAEnF,qDAAqD;AACrD,MAAM,MAAM,aAAa,GACnB,aAAa,GACb,aAAa,GACb,mBAAmB,CAAC;AAE1B,sFAAsF;AACtF,MAAM,MAAM,WAAW,GACjB,wBAAwB,GACxB,wBAAwB,GACxB,8BAA8B,GAC9B,wBAAwB,CAAC;AAE/B,0CAA0C;AAC1C,MAAM,MAAM,UAAU,GAChB,WAAW,GACX,WAAW,GACX,QAAQ,GACR,MAAM,CAAC;AAEb,yDAAyD;AACzD,MAAM,MAAM,eAAe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B,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;CAChC;AAED,8DAA8D;AAC9D,MAAM,WAAW,aAAa;IAC1B,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,EAAE,YAAY,CAAC;IAC1B,+BAA+B;IAC/B,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,yDAAyD;IACzD,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;IAC1C,qDAAqD;IACrD,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,iDAAiD;IACjD,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAE/B;;;OAGG;IACH,IAAI,IAAI,OAAO,CAAC,eAAe,CAAC,CAAC;IAEjC;;;OAGG;IACH,KAAK,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvC;;;OAGG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB,uEAAuE;IACvE,EAAE,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,EAAE,QAAQ,EAAE,CAAC,GAAG,EAAE,WAAW,GAAG,QAAQ,KAAK,IAAI,GAAG,IAAI,CAAC;CACvF"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Domain types for @browsercore/tls.
|
|
3
|
+
*
|
|
4
|
+
* This package owns TLS 1.3 (and 1.2 fallback) protocol logic. It knows about
|
|
5
|
+
* byte streams (@browsercore/transport) and cryptographic primitives (@browsercore/crypto)
|
|
6
|
+
* but NEVER imports node:crypto directly — that boundary is @browsercore/crypto's job.
|
|
7
|
+
*/
|
|
8
|
+
/** TLS 1.2 protocol version constant. */
|
|
9
|
+
export const TLS_1_2 = { name: "TLS 1.2", wire: 0x0303 };
|
|
10
|
+
/** TLS 1.3 protocol version constant. */
|
|
11
|
+
export const TLS_1_3 = { name: "TLS 1.3", wire: 0x0304 };
|
|
12
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAgBH,yCAAyC;AACzC,MAAM,CAAC,MAAM,OAAO,GAAoB,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAW,CAAC;AAEnF,yCAAyC;AACzC,MAAM,CAAC,MAAM,OAAO,GAAoB,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAW,CAAC"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Small shared helpers for @browsercore/tls.
|
|
3
|
+
*
|
|
4
|
+
* Kept dependency-free so every package can copy the pattern without pulling in
|
|
5
|
+
* cross-package imports.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Exhaustiveness check for `switch`/`if-else` over discriminated unions.
|
|
9
|
+
* Call in the `default` branch: `default: assertNever(x)`.
|
|
10
|
+
* Adding a new union member forces every handler to compile-error until handled.
|
|
11
|
+
*/
|
|
12
|
+
export declare function assertNever(x: never): never;
|
|
13
|
+
/** Monotonic-ish unique id generator (not cryptographically random). */
|
|
14
|
+
export declare function createId(prefix: string): string;
|
|
15
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;GAIG;AAEH,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,GAAG,KAAK,CAE3C;AAED,wEAAwE;AACxE,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE/C"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Small shared helpers for @browsercore/tls.
|
|
3
|
+
*
|
|
4
|
+
* Kept dependency-free so every package can copy the pattern without pulling in
|
|
5
|
+
* cross-package imports.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Exhaustiveness check for `switch`/`if-else` over discriminated unions.
|
|
9
|
+
* Call in the `default` branch: `default: assertNever(x)`.
|
|
10
|
+
* Adding a new union member forces every handler to compile-error until handled.
|
|
11
|
+
*/
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
13
|
+
export function assertNever(x) {
|
|
14
|
+
throw new Error(`Unexpected value: ${JSON.stringify(x)}`);
|
|
15
|
+
}
|
|
16
|
+
/** Monotonic-ish unique id generator (not cryptographically random). */
|
|
17
|
+
export function createId(prefix) {
|
|
18
|
+
return `${prefix}_${Date.now().toString(36)}_${Math.floor(Math.random() * 1e6).toString(36)}`;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;GAIG;AACH,6DAA6D;AAC7D,MAAM,UAAU,WAAW,CAAC,CAAQ;IAChC,MAAM,IAAI,KAAK,CAAC,qBAAqB,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAC9D,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,QAAQ,CAAC,MAAc;IACnC,OAAO,GAAG,MAAM,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;AAClG,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@browsercore/tls",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TLS 1.3 (and 1.2 fallback) client implemented entirely in TypeScript. Depends on @browsercore/transport and @browsercore/crypto — never node:crypto directly.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/jverneuer/browsercore-tls.git"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://github.com/jverneuer/browsercore-tls#readme",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/jverneuer/browsercore-tls/issues"
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"LICENSE",
|
|
26
|
+
"README.md"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"clean": "rm -rf dist",
|
|
30
|
+
"build": "tsc -p tsconfig.build.json",
|
|
31
|
+
"prepublishOnly": "npm run clean && npm run build",
|
|
32
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
33
|
+
"test": "vitest run"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/node": "^20.14.0",
|
|
37
|
+
"typescript": "^5.6.3",
|
|
38
|
+
"vitest": "^2.1.8"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public",
|
|
42
|
+
"registry": "https://registry.npmjs.org/"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@browsercore/crypto": "^0.1.0",
|
|
46
|
+
"@browsercore/transport": "^0.1.0"
|
|
47
|
+
},
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": ">=24.0.0"
|
|
50
|
+
}
|
|
51
|
+
}
|