Phase A complete: createShade() one-liner with auto-establish, auto-publish,
and auto-replenish.
M-Magic 1-4 rolled into @shade/sdk:
- createShade() factory with config validation and storage resolution
(memory | sqlite:... | { type: 'postgres', url: ... } | explicit instance)
- Shade class wraps crypto + storage + session manager + transport
- Auto-publish: initialize() automatically registers with the prekey server
- Auto-establish: send() transparently fetches bundles and creates sessions
on first message to a new peer
- Per-address mutex serializes concurrent sends to prevent ratchet corruption
- BackgroundTasks class for periodic replenishment + opt-in identity rotation
- rotate() rebuilds the transport with the new signing key so subsequent
signed operations work after rotation
- onMessage() handler API for incoming plaintext
API:
const shade = await createShade({ prekeyServer, storage });
await shade.send('bob', 'hello');
await shade.receive('alice', envelope);
shade.onMessage((from, msg) => ...);
await shade.rotate();
await shade.shutdown();
13 new SDK tests covering: happy path, auto-publish, two-process
conversation, onMessage handlers, concurrent sends, unknown peer,
fingerprint verification, shutdown, manual replenish, auto-replenish
off, rotate, and config validation.
233 tests passing, 0 failures.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
24 lines
602 B
TypeScript
24 lines
602 B
TypeScript
import { resolveConfig, type ShadeConfig } from './config.js';
|
|
import { Shade } from './shade.js';
|
|
|
|
/**
|
|
* Create and initialize a Shade instance in one call.
|
|
*
|
|
* ```ts
|
|
* const shade = await createShade({
|
|
* prekeyServer: 'https://shade.example.com',
|
|
* storage: 'sqlite:/data/shade.db',
|
|
* });
|
|
*
|
|
* await shade.send('bob@example.com', 'hello');
|
|
* ```
|
|
*
|
|
* See ShadeConfig for all options.
|
|
*/
|
|
export async function createShade(config: ShadeConfig): Promise<Shade> {
|
|
const resolved = resolveConfig(config);
|
|
const shade = new Shade(resolved);
|
|
await shade.initialize();
|
|
return shade;
|
|
}
|