import { Hono } from 'hono';
import { createShade } from '@shade/sdk';

const bob = await createShade({
  prekeyServer: '__PREKEY_SERVER__',
  storage: 'sqlite:./.shade/bob.db',
  address: 'bob',
});

console.log(`Bob ready. Fingerprint: ${await bob.fingerprint}`);

bob.onMessage((from, msg) => {
  console.log(`\n📨 [${from}] ${msg}\n`);
});

const app = new Hono();
app.post('/receive', async (c) => {
  const { from, envelope } = await c.req.json();
  await bob.receive(from, envelope);
  return c.json({ ok: true });
});

export default { port: 4001, fetch: app.fetch };
console.log('Bob listening on :4001');
