Files
scriptc/packages/runtime-wasm32-wasi/scripts/build.mjs
T
Chris Tate 2582e46e76 Support crypto.createECDH and ECDH.convertKey
crypto.createECDH returns a native ECDH handle backed by mbedTLS for
prime192v1, secp224r1, prime256v1, secp384r1, secp521r1, secp192k1,
secp224k1, secp256k1, brainpoolP256r1, brainpoolP384r1 and
brainpoolP512r1. generateKeys, computeSecret, getPublicKey,
getPrivateKey, setPrivateKey, setPublicKey and ECDH.convertKey follow
Node 24: compressed, uncompressed and hybrid points, input and output
encodings, the private key range, key pair validation, and Node's error
codes and messages.

Curve names follow OpenSSL's short-name lookup: names of other curves
from crypto.getCurves() are refused at compile time when literal and
throw a coded SC2020 error when computed, other OpenSSL short names
throw ERR_CRYPTO_OPERATION_FAILED, and unknown names throw
ERR_CRYPTO_INVALID_CURVE. Calls whose arguments no @types/node overload
accepts, and computeSecret(view, encoding), are refused at compile time.

The runtime unit scr_ecdh.c links, with the mbedTLS archive, only into
programs that use ECDH. wasm32-wasi builds refuse it.
2026-10-20 19:17:05 -05:00

48 lines
1.4 KiB
JavaScript

import { dirname } from "node:path";
import { fileURLToPath } from "node:url";
process.env.SCRIPTC_RUNTIME_PACK_ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
process.env.SCRIPTC_RUNTIME_PACK_CONFIG = JSON.stringify({
platform: "wasi",
// AbortSignal is portable here and dispatches through the EventTarget unit.
extraRuntimeSources: ["scr_abort.c", "scr_event_target.c"],
runtimeDefines: ["_GNU_SOURCE", "_WASI_EMULATED_SIGNAL", "_WASI_EMULATED_PROCESS_CLOCKS"],
omitRuntimeSources: ["scr_child.c"],
omitOptionalSources: [
"scr_event_target.c",
"scr_loop_kqueue.c",
"scr_loop_epoll.c",
"scr_loop_wsapoll.c",
"scr_net.c",
"scr_http.c",
"scr_http2.c",
"scr_dgram.c",
"scr_dns_promises.c",
"scr_watch.c",
"scr_tls_ca.c",
"scr_tls.c",
"scr_cipher.c",
"scr_ecdh.c",
"scr_wasm.c",
"scr_fetch.c",
],
omitArchives: ["mbedtls"],
compiler: "zig",
compilerArgs: ["cc"],
archiver: "zig",
archiverArgs: ["ar"],
target: {
name: "wasm32-wasi",
llvm_triple: "wasm32-unknown-wasi",
architecture: "wasm32",
object_format: "wasm",
minimum_os: "WASI Preview 1",
},
targetArgs: ["-target", "wasm32-wasi"],
compileFlags: [],
systemLibraries: [
{ name: "wasi-emulated-signal", predicate: true },
{ name: "wasi-emulated-process-clocks", predicate: true },
],
});
await import("../../runtime-pack-common/scripts/build.mjs");