@sproutboat/runtime 0.37.1 → 0.39.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.
@@ -0,0 +1,321 @@
1
+ // Monocypher version 4.0.2
2
+ //
3
+ // This file is dual-licensed. Choose whichever licence you want from
4
+ // the two licences listed below.
5
+ //
6
+ // The first licence is a regular 2-clause BSD licence. The second licence
7
+ // is the CC-0 from Creative Commons. It is intended to release Monocypher
8
+ // to the public domain. The BSD licence serves as a fallback option.
9
+ //
10
+ // SPDX-License-Identifier: BSD-2-Clause OR CC0-1.0
11
+ //
12
+ // ------------------------------------------------------------------------
13
+ //
14
+ // Copyright (c) 2017-2019, Loup Vaillant
15
+ // All rights reserved.
16
+ //
17
+ //
18
+ // Redistribution and use in source and binary forms, with or without
19
+ // modification, are permitted provided that the following conditions are
20
+ // met:
21
+ //
22
+ // 1. Redistributions of source code must retain the above copyright
23
+ // notice, this list of conditions and the following disclaimer.
24
+ //
25
+ // 2. Redistributions in binary form must reproduce the above copyright
26
+ // notice, this list of conditions and the following disclaimer in the
27
+ // documentation and/or other materials provided with the
28
+ // distribution.
29
+ //
30
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34
+ // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41
+ //
42
+ // ------------------------------------------------------------------------
43
+ //
44
+ // Written in 2017-2019 by Loup Vaillant
45
+ //
46
+ // To the extent possible under law, the author(s) have dedicated all copyright
47
+ // and related neighboring rights to this software to the public domain
48
+ // worldwide. This software is distributed without any warranty.
49
+ //
50
+ // You should have received a copy of the CC0 Public Domain Dedication along
51
+ // with this software. If not, see
52
+ // <https://creativecommons.org/publicdomain/zero/1.0/>
53
+
54
+ #ifndef MONOCYPHER_H
55
+ #define MONOCYPHER_H
56
+
57
+ #include <stddef.h>
58
+ #include <stdint.h>
59
+
60
+ #ifdef MONOCYPHER_CPP_NAMESPACE
61
+ namespace MONOCYPHER_CPP_NAMESPACE {
62
+ #elif defined(__cplusplus)
63
+ extern "C" {
64
+ #endif
65
+
66
+ // Constant time comparisons
67
+ // -------------------------
68
+
69
+ // Return 0 if a and b are equal, -1 otherwise
70
+ int crypto_verify16(const uint8_t a[16], const uint8_t b[16]);
71
+ int crypto_verify32(const uint8_t a[32], const uint8_t b[32]);
72
+ int crypto_verify64(const uint8_t a[64], const uint8_t b[64]);
73
+
74
+
75
+ // Erase sensitive data
76
+ // --------------------
77
+ void crypto_wipe(void *secret, size_t size);
78
+
79
+
80
+ // Authenticated encryption
81
+ // ------------------------
82
+ void crypto_aead_lock(uint8_t *cipher_text,
83
+ uint8_t mac [16],
84
+ const uint8_t key [32],
85
+ const uint8_t nonce[24],
86
+ const uint8_t *ad, size_t ad_size,
87
+ const uint8_t *plain_text, size_t text_size);
88
+ int crypto_aead_unlock(uint8_t *plain_text,
89
+ const uint8_t mac [16],
90
+ const uint8_t key [32],
91
+ const uint8_t nonce[24],
92
+ const uint8_t *ad, size_t ad_size,
93
+ const uint8_t *cipher_text, size_t text_size);
94
+
95
+ // Authenticated stream
96
+ // --------------------
97
+ typedef struct {
98
+ uint64_t counter;
99
+ uint8_t key[32];
100
+ uint8_t nonce[8];
101
+ } crypto_aead_ctx;
102
+
103
+ void crypto_aead_init_x(crypto_aead_ctx *ctx,
104
+ const uint8_t key[32], const uint8_t nonce[24]);
105
+ void crypto_aead_init_djb(crypto_aead_ctx *ctx,
106
+ const uint8_t key[32], const uint8_t nonce[8]);
107
+ void crypto_aead_init_ietf(crypto_aead_ctx *ctx,
108
+ const uint8_t key[32], const uint8_t nonce[12]);
109
+
110
+ void crypto_aead_write(crypto_aead_ctx *ctx,
111
+ uint8_t *cipher_text,
112
+ uint8_t mac[16],
113
+ const uint8_t *ad , size_t ad_size,
114
+ const uint8_t *plain_text, size_t text_size);
115
+ int crypto_aead_read(crypto_aead_ctx *ctx,
116
+ uint8_t *plain_text,
117
+ const uint8_t mac[16],
118
+ const uint8_t *ad , size_t ad_size,
119
+ const uint8_t *cipher_text, size_t text_size);
120
+
121
+
122
+ // General purpose hash (BLAKE2b)
123
+ // ------------------------------
124
+
125
+ // Direct interface
126
+ void crypto_blake2b(uint8_t *hash, size_t hash_size,
127
+ const uint8_t *message, size_t message_size);
128
+
129
+ void crypto_blake2b_keyed(uint8_t *hash, size_t hash_size,
130
+ const uint8_t *key, size_t key_size,
131
+ const uint8_t *message, size_t message_size);
132
+
133
+ // Incremental interface
134
+ typedef struct {
135
+ // Do not rely on the size or contents of this type,
136
+ // for they may change without notice.
137
+ uint64_t hash[8];
138
+ uint64_t input_offset[2];
139
+ uint64_t input[16];
140
+ size_t input_idx;
141
+ size_t hash_size;
142
+ } crypto_blake2b_ctx;
143
+
144
+ void crypto_blake2b_init(crypto_blake2b_ctx *ctx, size_t hash_size);
145
+ void crypto_blake2b_keyed_init(crypto_blake2b_ctx *ctx, size_t hash_size,
146
+ const uint8_t *key, size_t key_size);
147
+ void crypto_blake2b_update(crypto_blake2b_ctx *ctx,
148
+ const uint8_t *message, size_t message_size);
149
+ void crypto_blake2b_final(crypto_blake2b_ctx *ctx, uint8_t *hash);
150
+
151
+
152
+ // Password key derivation (Argon2)
153
+ // --------------------------------
154
+ #define CRYPTO_ARGON2_D 0
155
+ #define CRYPTO_ARGON2_I 1
156
+ #define CRYPTO_ARGON2_ID 2
157
+
158
+ typedef struct {
159
+ uint32_t algorithm; // Argon2d, Argon2i, Argon2id
160
+ uint32_t nb_blocks; // memory hardness, >= 8 * nb_lanes
161
+ uint32_t nb_passes; // CPU hardness, >= 1 (>= 3 recommended for Argon2i)
162
+ uint32_t nb_lanes; // parallelism level (single threaded anyway)
163
+ } crypto_argon2_config;
164
+
165
+ typedef struct {
166
+ const uint8_t *pass;
167
+ const uint8_t *salt;
168
+ uint32_t pass_size;
169
+ uint32_t salt_size; // 16 bytes recommended
170
+ } crypto_argon2_inputs;
171
+
172
+ typedef struct {
173
+ const uint8_t *key; // may be NULL if no key
174
+ const uint8_t *ad; // may be NULL if no additional data
175
+ uint32_t key_size; // 0 if no key (32 bytes recommended otherwise)
176
+ uint32_t ad_size; // 0 if no additional data
177
+ } crypto_argon2_extras;
178
+
179
+ extern const crypto_argon2_extras crypto_argon2_no_extras;
180
+
181
+ void crypto_argon2(uint8_t *hash, uint32_t hash_size, void *work_area,
182
+ crypto_argon2_config config,
183
+ crypto_argon2_inputs inputs,
184
+ crypto_argon2_extras extras);
185
+
186
+
187
+ // Key exchange (X-25519)
188
+ // ----------------------
189
+
190
+ // Shared secrets are not quite random.
191
+ // Hash them to derive an actual shared key.
192
+ void crypto_x25519_public_key(uint8_t public_key[32],
193
+ const uint8_t secret_key[32]);
194
+ void crypto_x25519(uint8_t raw_shared_secret[32],
195
+ const uint8_t your_secret_key [32],
196
+ const uint8_t their_public_key [32]);
197
+
198
+ // Conversion to EdDSA
199
+ void crypto_x25519_to_eddsa(uint8_t eddsa[32], const uint8_t x25519[32]);
200
+
201
+ // scalar "division"
202
+ // Used for OPRF. Be aware that exponential blinding is less secure
203
+ // than Diffie-Hellman key exchange.
204
+ void crypto_x25519_inverse(uint8_t blind_salt [32],
205
+ const uint8_t private_key[32],
206
+ const uint8_t curve_point[32]);
207
+
208
+ // "Dirty" versions of x25519_public_key().
209
+ // Use with crypto_elligator_rev().
210
+ // Leaks 3 bits of the private key.
211
+ void crypto_x25519_dirty_small(uint8_t pk[32], const uint8_t sk[32]);
212
+ void crypto_x25519_dirty_fast (uint8_t pk[32], const uint8_t sk[32]);
213
+
214
+
215
+ // Signatures
216
+ // ----------
217
+
218
+ // EdDSA with curve25519 + BLAKE2b
219
+ void crypto_eddsa_key_pair(uint8_t secret_key[64],
220
+ uint8_t public_key[32],
221
+ uint8_t seed[32]);
222
+ void crypto_eddsa_sign(uint8_t signature [64],
223
+ const uint8_t secret_key[64],
224
+ const uint8_t *message, size_t message_size);
225
+ int crypto_eddsa_check(const uint8_t signature [64],
226
+ const uint8_t public_key[32],
227
+ const uint8_t *message, size_t message_size);
228
+
229
+ // Conversion to X25519
230
+ void crypto_eddsa_to_x25519(uint8_t x25519[32], const uint8_t eddsa[32]);
231
+
232
+ // EdDSA building blocks
233
+ void crypto_eddsa_trim_scalar(uint8_t out[32], const uint8_t in[32]);
234
+ void crypto_eddsa_reduce(uint8_t reduced[32], const uint8_t expanded[64]);
235
+ void crypto_eddsa_mul_add(uint8_t r[32],
236
+ const uint8_t a[32],
237
+ const uint8_t b[32],
238
+ const uint8_t c[32]);
239
+ void crypto_eddsa_scalarbase(uint8_t point[32], const uint8_t scalar[32]);
240
+ int crypto_eddsa_check_equation(const uint8_t signature[64],
241
+ const uint8_t public_key[32],
242
+ const uint8_t h_ram[32]);
243
+
244
+
245
+ // Chacha20
246
+ // --------
247
+
248
+ // Specialised hash.
249
+ // Used to hash X25519 shared secrets.
250
+ void crypto_chacha20_h(uint8_t out[32],
251
+ const uint8_t key[32],
252
+ const uint8_t in [16]);
253
+
254
+ // Unauthenticated stream cipher.
255
+ // Don't forget to add authentication.
256
+ uint64_t crypto_chacha20_djb(uint8_t *cipher_text,
257
+ const uint8_t *plain_text,
258
+ size_t text_size,
259
+ const uint8_t key[32],
260
+ const uint8_t nonce[8],
261
+ uint64_t ctr);
262
+ uint32_t crypto_chacha20_ietf(uint8_t *cipher_text,
263
+ const uint8_t *plain_text,
264
+ size_t text_size,
265
+ const uint8_t key[32],
266
+ const uint8_t nonce[12],
267
+ uint32_t ctr);
268
+ uint64_t crypto_chacha20_x(uint8_t *cipher_text,
269
+ const uint8_t *plain_text,
270
+ size_t text_size,
271
+ const uint8_t key[32],
272
+ const uint8_t nonce[24],
273
+ uint64_t ctr);
274
+
275
+
276
+ // Poly 1305
277
+ // ---------
278
+
279
+ // This is a *one time* authenticator.
280
+ // Disclosing the mac reveals the key.
281
+ // See crypto_lock() on how to use it properly.
282
+
283
+ // Direct interface
284
+ void crypto_poly1305(uint8_t mac[16],
285
+ const uint8_t *message, size_t message_size,
286
+ const uint8_t key[32]);
287
+
288
+ // Incremental interface
289
+ typedef struct {
290
+ // Do not rely on the size or contents of this type,
291
+ // for they may change without notice.
292
+ uint8_t c[16]; // chunk of the message
293
+ size_t c_idx; // How many bytes are there in the chunk.
294
+ uint32_t r [4]; // constant multiplier (from the secret key)
295
+ uint32_t pad[4]; // random number added at the end (from the secret key)
296
+ uint32_t h [5]; // accumulated hash
297
+ } crypto_poly1305_ctx;
298
+
299
+ void crypto_poly1305_init (crypto_poly1305_ctx *ctx, const uint8_t key[32]);
300
+ void crypto_poly1305_update(crypto_poly1305_ctx *ctx,
301
+ const uint8_t *message, size_t message_size);
302
+ void crypto_poly1305_final (crypto_poly1305_ctx *ctx, uint8_t mac[16]);
303
+
304
+
305
+ // Elligator 2
306
+ // -----------
307
+
308
+ // Elligator mappings proper
309
+ void crypto_elligator_map(uint8_t curve [32], const uint8_t hidden[32]);
310
+ int crypto_elligator_rev(uint8_t hidden[32], const uint8_t curve [32],
311
+ uint8_t tweak);
312
+
313
+ // Easy to use key pair generation
314
+ void crypto_elligator_key_pair(uint8_t hidden[32], uint8_t secret_key[32],
315
+ uint8_t seed[32]);
316
+
317
+ #ifdef __cplusplus
318
+ }
319
+ #endif
320
+
321
+ #endif // MONOCYPHER_H
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The compatibility date from which `crypto.subtle` follows workerd's surface (RSA, ECDSA, Ed25519,
3
+ * AES, key import and export, DOMException errors). A placeholder: the maintainers choose the
4
+ * date. Keep it equal to `__SB_SUBTLE_DATE` in `native-fetch-prelude.js`; a test checks that.
5
+ */
6
+ export const SUBTLE_DATE = "2026-11-06";
package/src/wrap.ts CHANGED
@@ -205,6 +205,36 @@ export function neutraliseExports(source: string): string | null {
205
205
  * leaks that change to later requests. Freeze upstream once Porffor supports
206
206
  * Object.freeze in native mode.
207
207
  */
208
+ /**
209
+ * What a handler needs of crypto.subtle: `"always"` (the default for the embedded transport) leaves the prelude as it is, which
210
+ * is what a shared template needs (sproutd compiles apps against one prelude). `"auto"` drops the
211
+ * workerd-style crypto.subtle (its JavaScript, and the BearSSL and Monocypher C behind it) from a
212
+ * handler whose source never mentions `subtle`, `DigestStream` or `CryptoKey`: such a handler cannot
213
+ * reach it, and the code is about 330 KB of a 5.3 MB standalone binary and about 2 s of its build.
214
+ * A handler that reaches crypto.subtle without naming it (a computed property name) gets the
215
+ * digest/HMAC/PBKDF2 subset that earlier dates have.
216
+ */
217
+ export type SubtleMode = "always" | "auto";
218
+
219
+ const SUBTLE_BLOCKS: Array<[string, string]> = [
220
+ ["// SUBTLE-JS:BEGIN", "// SUBTLE-JS:END"],
221
+ ["// SUBTLE:BEGIN", "// SUBTLE:END"],
222
+ ];
223
+ /** The prelude without workerd-style crypto.subtle. Throws if a marker is missing: a silent no-op would ship the code. */
224
+ export function pruneSubtle(prelude: string): string {
225
+ let out = prelude;
226
+ for (const [begin, end] of SUBTLE_BLOCKS) {
227
+ const start = out.indexOf(begin);
228
+ const stop = out.indexOf(end, start);
229
+ if (start < 0 || stop < 0) {
230
+ throw new Error(`the prelude has no ${begin} ... ${end} block to prune`);
231
+ }
232
+ out = out.slice(0, start) + out.slice(out.indexOf("\n", stop) + 1);
233
+ }
234
+ return out;
235
+ }
236
+ export const reachesSubtle = (source: string) => /\b(?:subtle|DigestStream|CryptoKey)\b/.test(source);
237
+
208
238
  export function wrapNativeFetchHandler(
209
239
  source: string,
210
240
  prelude: string,
@@ -224,7 +254,17 @@ export function wrapNativeFetchHandler(
224
254
  * own self-describing identity rather than a broker round trip.
225
255
  */
226
256
  versionMetadata?: { binding: string; id: string; tag: string; timestamp: string },
257
+ subtle?: SubtleMode,
227
258
  ): string {
259
+ // The shared template (sproutd) is the embedded transport and needs it all; a broker build links BearSSL only for
260
+ // a handler that uses crypto.subtle (the CLI does that), so it defaults to pruning.
261
+ // A prelude without the block (a test stub) is left alone; prune.test.ts holds the real one to it.
262
+ if (
263
+ (subtle ?? (transport === "embedded" ? "always" : "auto")) === "auto" &&
264
+ !reachesSubtle(source) &&
265
+ prelude.includes("// SUBTLE-JS:BEGIN")
266
+ )
267
+ prelude = pruneSubtle(prelude);
228
268
  const neutralised = neutraliseExports(inlineWorkersImports(source));
229
269
  // A WorkerEntrypoint may serve only RPC, and a Worker only scheduled() or queue(), with
230
270
  // no fetch() at all, as in workerd.
@@ -0,0 +1,70 @@
1
+ import { createHash } from "node:crypto";
2
+ import { existsSync } from "node:fs";
3
+ import { mkdir, readdir, rename, rm, writeFile } from "node:fs/promises";
4
+ import { homedir } from "node:os";
5
+ import { join, resolve } from "node:path";
6
+
7
+ // The prelude carries crypto.subtle's native half on every transport, so a test that compiles a
8
+ // handler using crypto.subtle needs BearSSL on the include path and link line, as the CLI arranges
9
+ // for a build. Same pinned source as the CLI's src/bearssl.ts; built once into the toolchain cache.
10
+ const VERSION = "0.6";
11
+ const URL_ = `https://bearssl.org/bearssl-${VERSION}.tar.gz`;
12
+ const SHA256 = "6705bba1714961b41a728dfc5debbe348d2966c117649392f8c8139efc83ff14";
13
+
14
+ const walk = async (dir: string): Promise<string[]> =>
15
+ (
16
+ await Promise.all(
17
+ (await readdir(dir, { withFileTypes: true })).map((entry) =>
18
+ entry.isDirectory()
19
+ ? walk(join(dir, entry.name))
20
+ : Promise.resolve(entry.name.endsWith(".c") ? [join(dir, entry.name)] : []),
21
+ ),
22
+ )
23
+ ).flat();
24
+
25
+ /** `SB_EXTRA_CFLAGS` and `SB_EXTRA_LINK` for a host Porffor compile that uses crypto.subtle. */
26
+ export async function bearsslEnv(): Promise<{ SB_EXTRA_CFLAGS: string; SB_EXTRA_LINK: string }> {
27
+ const root = resolve(
28
+ process.env.SPROUTBOAT_TOOLCHAIN_CACHE ?? join(homedir(), ".cache/sproutboat"),
29
+ `bearssl-${VERSION}-test`,
30
+ );
31
+ const tree = join(root, `bearssl-${VERSION}`);
32
+ const objects = join(root, "obj");
33
+ const marker = join(objects, ".complete");
34
+ if (!existsSync(marker)) {
35
+ await mkdir(root, { recursive: true });
36
+ const response = await fetch(URL_);
37
+ if (!response.ok) throw new Error(`could not download ${URL_}: HTTP ${response.status}`);
38
+ const bytes = Buffer.from(await response.arrayBuffer());
39
+ if (createHash("sha256").update(bytes).digest("hex") !== SHA256) throw new Error("BearSSL checksum mismatch");
40
+ await writeFile(join(root, "bearssl.tar.gz"), bytes);
41
+ await rm(tree, { recursive: true, force: true });
42
+ const untar = Bun.spawnSync(["tar", "xzf", join(root, "bearssl.tar.gz"), "-C", root]);
43
+ if (untar.exitCode !== 0) throw new Error(`could not unpack BearSSL: ${untar.stderr}`);
44
+ const stage = `${objects}.${process.pid}`;
45
+ await rm(stage, { recursive: true, force: true });
46
+ await mkdir(stage, { recursive: true });
47
+ const cc = process.env.CC ?? "cc";
48
+ const sources = await walk(join(tree, "src"));
49
+ const queue = [...sources];
50
+ const worker = async () => {
51
+ for (let file = queue.pop(); file !== undefined; file = queue.pop()) {
52
+ const out = join(stage, `${file.split("/").pop()!.replace(/\.c$/, "")}.o`);
53
+ const run = Bun.spawn([cc, "-Os", "-I", join(tree, "inc"), "-I", join(tree, "src"), "-c", file, "-o", out], {
54
+ stderr: "pipe",
55
+ });
56
+ if ((await run.exited) !== 0)
57
+ throw new Error(`could not compile ${file}: ${await new Response(run.stderr).text()}`);
58
+ }
59
+ };
60
+ await Promise.all(Array.from({ length: 8 }, worker));
61
+ await writeFile(join(stage, ".complete"), "");
62
+ await rm(objects, { recursive: true, force: true });
63
+ await rename(stage, objects);
64
+ }
65
+ const names = (await readdir(objects)).filter((name) => name.endsWith(".o")).sort();
66
+ return {
67
+ SB_EXTRA_CFLAGS: `-I ${join(tree, "inc")}`,
68
+ SB_EXTRA_LINK: names.map((name) => join(objects, name)).join(" "),
69
+ };
70
+ }
@@ -3,6 +3,7 @@ import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
3
3
  import { tmpdir } from "node:os";
4
4
  import { join, resolve } from "node:path";
5
5
  import { ensurePorffor } from "../../toolchain/src/acquire";
6
+ import { bearsslEnv } from "./bearssl";
6
7
  import { preludePath, TRANSPORT_MARKER, transportPath, wrapNativeFetchHandler } from "../src/wrap";
7
8
 
8
9
  // These values come from Bun WebCrypto and node:crypto, not from the runtime
@@ -71,26 +72,28 @@ try {
71
72
  const node = Bun.which("node");
72
73
  if (!node) throw new Error("native crypto test needs node on PATH");
73
74
 
74
- const [core, broker] = await Promise.all([
75
- readFile(preludePath, "utf8"),
76
- readFile(transportPath("broker"), "utf8"),
77
- ]);
75
+ const [core, broker] = await Promise.all([readFile(preludePath, "utf8"), readFile(transportPath("broker"), "utf8")]);
78
76
  assert(core.includes(TRANSPORT_MARKER), "runtime prelude is missing its transport marker");
79
77
  const prelude = core.replace(TRANSPORT_MARKER, broker);
80
78
  const generated = join(workdir, "crypto.generated.js");
81
79
  const binary = join(workdir, "crypto-native");
82
80
  // This is a direct ESM import into Porffor, with no bundler in front of it.
83
- await writeFile(join(workdir, "crypto-helper.js"),
84
- "export const keyBytes = () => Uint8Array.from({ length: 16 }, (_, index) => index + 1);\n");
81
+ await writeFile(
82
+ join(workdir, "crypto-helper.js"),
83
+ "export const keyBytes = () => Uint8Array.from({ length: 16 }, (_, index) => index + 1);\n",
84
+ );
85
85
  await writeFile(generated, wrapNativeFetchHandler(handler, prelude));
86
86
  await rm(binary, { force: true });
87
87
 
88
- const compile = Bun.spawn([node, resolve(porffor, "runtime/index.js"), "native", generated, "-o", binary, "-s", "-O0"], {
89
- cwd: workdir,
90
- env: process.env,
91
- stdout: "pipe",
92
- stderr: "pipe",
93
- });
88
+ const compile = Bun.spawn(
89
+ [node, resolve(porffor, "runtime/index.js"), "native", generated, "-o", binary, "-s", "-O0"],
90
+ {
91
+ cwd: workdir,
92
+ env: { ...process.env, ...(await bearsslEnv()) },
93
+ stdout: "pipe",
94
+ stderr: "pipe",
95
+ },
96
+ );
94
97
  const [exitCode, stdout, stderr] = await Promise.all([
95
98
  compile.exited,
96
99
  new Response(compile.stdout).text(),
@@ -4,6 +4,7 @@ import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
4
4
  import { tmpdir } from "node:os";
5
5
  import { join, resolve } from "node:path";
6
6
  import { ensurePorffor } from "../../toolchain/src/acquire";
7
+ import { bearsslEnv } from "./bearssl";
7
8
  import { preludePath, TRANSPORT_MARKER, transportPath, wrapNativeFetchHandler } from "../src/wrap";
8
9
 
9
10
  // The pieces of a JWT check (base64url decode, TextEncoder, HMAC verify) against values that do
@@ -290,7 +291,7 @@ try {
290
291
  [node, resolve(porffor, "runtime/index.js"), "native", generated, "-o", binary, "-s", "-O0"],
291
292
  {
292
293
  cwd: workdir,
293
- env: process.env,
294
+ env: { ...process.env, ...(await bearsslEnv()) },
294
295
  stdout: "pipe",
295
296
  stderr: "pipe",
296
297
  },