enbox
A TypeScript SDK for decentralised identity and personal data storage. Your users own their data. You build the experience.
Built with Bun
import {
createConnectionStore,
defineApplicationManifest,
defineProtocol,
recordCodecs,
} from '@enbox/api';
// Define a typed protocol
const NotesDefinition = {
protocol: 'https://example.com/notes',
published: true,
types: {
note: {
schema: 'https://example.com/note',
dataFormats: ['application/json'],
},
},
structure: { note: {} },
} as const;
const Notes = defineProtocol(NotesDefinition, {
note: recordCodecs.json<{ title: string; body: string }>(),
});
// Connect and use the protocol
const application = defineApplicationManifest({ protocols: [Notes] } as const);
const store = createConnectionStore({ application });
let snapshot = await store.initialize();
if (snapshot.phase === 'disconnected') {
snapshot = await store.connectVault({ createIdentity: true });
}
if (snapshot.phase !== 'connected') {
throw snapshot.error ?? new Error('Connection was not established.');
}
const notes = snapshot.enbox.using(Notes);
// Create
const record = await notes.records.create('note', {
data: { title: 'First note', body: 'Hello from Enbox!' },
});
// Read
const data = await record.value();
// Update
await record.update({
data: { title: 'Updated note', body: 'Changed.' },
});
// Query
const { records } = await notes.records.query('note');
// Delete
await record.delete();
// Sign out and release app-lifetime resources
await store.disconnect();
await store.dispose();Decentralised Identity
DID-based identity that users own. No central account server. Supports did:dht, did:jwk, did:key, and did:web.
Personal Data Vaults
Data stored in Decentralised Web Nodes. Users choose where their data lives. Sync across devices automatically.
Type-Safe Protocols
Define DWN protocols with TypeScript types. Compile-time checks for paths, schemas, and record data.
End-to-End Encryption
Records encrypted with ECDH key agreement and AES-256-GCM content encryption. Per-protocol encryption policies.
Offline-First Sync
Durable local records stay usable offline and converge with remote DWNs when connectivity returns.
Self-Hostable Server
Run your own DWN server with PostgreSQL, MySQL, or SQLite. Rate limiting, quotas, and admin dashboard included.