fix(broker): libsodium dynamic import — extract .default for bun
Some checks failed
CI / Lint (push) Has been cancelled
CI / Typecheck (push) Has been cancelled
CI / Broker tests (Postgres) (push) Has been cancelled
CI / Docker build (linux/amd64) (push) Has been cancelled

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) <noreply@anthropic.com>
This commit is contained in:
Alejandro Gutiérrez
2026-05-02 21:15:37 +01:00
parent 3c35932191
commit d871988084

View File

@@ -634,7 +634,7 @@ async function generateTopicKeyBundle(): Promise<{
senderPubkey: Uint8Array; senderPubkey: Uint8Array;
senderPubkeyHex: string; senderPubkeyHex: string;
}> { }> {
const sodium = await import("libsodium-wrappers"); const sodium = (await import("libsodium-wrappers")).default;
await sodium.ready; await sodium.ready;
const topicKey = sodium.randombytes_buf(32); const topicKey = sodium.randombytes_buf(32);
const sender = sodium.crypto_box_keypair(); const sender = sodium.crypto_box_keypair();
@@ -674,7 +674,7 @@ async function sealTopicKeyForMember(args: {
.where(eq(memberTable.id, args.memberId)); .where(eq(memberTable.id, args.memberId));
if (!member) return; if (!member) return;
const sodium = await import("libsodium-wrappers"); const sodium = (await import("libsodium-wrappers")).default;
await sodium.ready; await sodium.ready;
let recipientX25519: Uint8Array; let recipientX25519: Uint8Array;
try { try {