enbox docs
Packages

@enbox/browser

Browser-first Enbox entrypoint for app APIs, auth, wallet connect, and DWeb helpers.

@enbox/browser is the browser-first package for Enbox apps. It re-exports the main app API from @enbox/api, auth/session helpers from @enbox/auth, and browser-only connect and DWeb utilities.

Installation

bun add @enbox/browser

Usage

import {
  BrowserConnectHandler,
  createConnectionStore,
  defineApplicationManifest,
} from '@enbox/browser';

const application = defineApplicationManifest({
  protocols: [NotesProtocol],
} as const);
const store = createConnectionStore({
  application,
  connectHandler: BrowserConnectHandler({ appName: 'Notes' }),
});

let snapshot = await store.initialize();
if (snapshot.phase === 'disconnected') {
  snapshot = await store.connect();
}
if (snapshot.phase !== 'connected') {
  throw snapshot.error ?? new Error('Connection was not established.');
}

const enbox = snapshot.enbox;

// ...use enbox...

// On sign-out and application shutdown:
await store.disconnect();
await store.dispose();

This is the delegated wallet flow. To create a local owner identity, omit connectHandler and call store.connectVault({ createIdentity: true }). The manifest-backed store owns restoration, refresh, facade replacement, and teardown; see the @enbox/api guide.

Browser entrypoint

The package root has a browser condition that resolves to dist/browser.mjs. Apps and service-worker builds can use the bare @enbox/browser import without adding Enbox-specific Node global shims.

See Browser & bundlers for bundler and storage details.

Key exports

ExportDescription
EnboxHigh-level app API from @enbox/api
createConnectionStore()Application connection lifecycle and observable snapshots
defineProtocol()Type-safe protocol definition helper
recordCodecsJSON, text, bytes, Blob, and private-file envelope codecs
AuthManagerAuth/session lifecycle from @enbox/auth
BrowserConnectHandlerBrowser wallet/connect handler
connectViaPopup()Low-level DWeb Connect popup handshake
activatePolyfills()DRL and DWeb browser feature activation
runConnectModal()Built-in wallet/connect method selector

On this page