From d871988084888d3327c19462b2b7183f3c54fe4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Guti=C3=A9rrez?= <35082514+alezmad@users.noreply.github.com> Date: Sat, 2 May 2026 21:15:37 +0100 Subject: [PATCH] =?UTF-8?q?fix(broker):=20libsodium=20dynamic=20import=20?= =?UTF-8?q?=E2=80=94=20extract=20.default=20for=20bun?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit await import('libsodium-wrappers') returns the namespace object in bun, not the sodium API. randombytes_buf et al. live on .default. Without this, every topic_create on the deployed broker errored with 'sodium.randombytes_buf is not a function' and the WS handler silently dropped — CLI saw a 5s timeout. Confirmed via broker docker logs: warn ws message error: sodium.randombytes_buf is not a function Same destructure pattern as crypto.ts (which uses the synchronous default import). Co-Authored-By: Claude Opus 4.7 (1M context) --- apps/broker/src/broker.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/broker/src/broker.ts b/apps/broker/src/broker.ts index a5eefd4..4f25113 100644 --- a/apps/broker/src/broker.ts +++ b/apps/broker/src/broker.ts @@ -634,7 +634,7 @@ async function generateTopicKeyBundle(): Promise<{ senderPubkey: Uint8Array; senderPubkeyHex: string; }> { - const sodium = await import("libsodium-wrappers"); + const sodium = (await import("libsodium-wrappers")).default; await sodium.ready; const topicKey = sodium.randombytes_buf(32); const sender = sodium.crypto_box_keypair(); @@ -674,7 +674,7 @@ async function sealTopicKeyForMember(args: { .where(eq(memberTable.id, args.memberId)); if (!member) return; - const sodium = await import("libsodium-wrappers"); + const sodium = (await import("libsodium-wrappers")).default; await sodium.ready; let recipientX25519: Uint8Array; try {