release(v4.9.0): relay-side encrypted blob primitive + SDK Profile namespace
Ships the Prism FR (encrypted-profile-storage-v4.9.md) as a generic relay-side encrypted blob primitive: deterministically-located, AEAD-sealed blobs keyed by a 32-byte slotId derived client-side via HKDF from the user's master key. Unlocks credential-only bootstrap of new devices into existing E2EE state — no QR, no physical access. Server: BlobStore interface + Memory/Sqlite/Postgres impls, createBlobRoutes for GET/PUT/DELETE /v1/blob/:slotId with TOFU pubkey auth and If-Match CAS (409/412 semantics). Mounted on the same Hono app as the inbox; SHADE_BLOB_PG_URL / SHADE_BLOB_DB_PATH / SHADE_DISABLE_BLOB env-var plumbing in standalone. SDK: createProfileNamespace high-level wrapper (HKDF derivation, random-nonce AEAD seal, slotId-bound AAD) + low-level BlobClient. Cross-platform test vectors in test-vectors/blob-storage.json. New errors: ConflictError (409), PreconditionFailedError (412). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
import type { Hono } from 'hono';
|
||||
import { Hono } from 'hono';
|
||||
import type { CryptoProvider } from '@shade/core';
|
||||
import { createInboxRoutes, type InboxRoutesOptions } from './routes.js';
|
||||
import { MemoryInboxStore } from './memory-store.js';
|
||||
import type { InboxStore } from './store.js';
|
||||
import { InboxServerEvents } from './events.js';
|
||||
import { createBlobRoutes, type BlobRoutesOptions } from './blob-routes.js';
|
||||
import { MemoryBlobStore } from './memory-blob-store.js';
|
||||
import type { BlobStore } from './blob-store.js';
|
||||
|
||||
export { createInboxRoutes } from './routes.js';
|
||||
export type { InboxRoutesOptions } from './routes.js';
|
||||
@@ -36,6 +39,10 @@ export { PresenceTracker } from './presence.js';
|
||||
export type { TrackedBridgeKind } from './presence.js';
|
||||
export { BridgeDeliveryLog } from './bridge-delivery-log.js';
|
||||
export type { BridgeDeliveryLogOptions } from './bridge-delivery-log.js';
|
||||
export { createBlobRoutes, DEFAULT_MAX_BLOB_BYTES } from './blob-routes.js';
|
||||
export type { BlobRoutesOptions } from './blob-routes.js';
|
||||
export { MemoryBlobStore } from './memory-blob-store.js';
|
||||
export type { BlobStore, BlobSlotRecord, PutBlobResult } from './blob-store.js';
|
||||
|
||||
/**
|
||||
* Create a standalone Shade Inbox Server.
|
||||
@@ -48,12 +55,21 @@ export type { BridgeDeliveryLogOptions } from './bridge-delivery-log.js';
|
||||
* const app = new Hono();
|
||||
* app.route('/', createInboxServer({ crypto }));
|
||||
*/
|
||||
export function createInboxServer(options: {
|
||||
crypto: CryptoProvider;
|
||||
store?: InboxStore;
|
||||
disableRateLimit?: boolean;
|
||||
events?: InboxServerEvents;
|
||||
} & Pick<InboxRoutesOptions, 'observability' | 'quota' | 'bridgeDeliveryLog'>): Hono {
|
||||
export function createInboxServer(
|
||||
options: {
|
||||
crypto: CryptoProvider;
|
||||
store?: InboxStore;
|
||||
disableRateLimit?: boolean;
|
||||
events?: InboxServerEvents;
|
||||
/**
|
||||
* V4.9 — when supplied, mounts the encrypted-blob primitive
|
||||
* (`/v1/blob/<slotId>`) on the same Hono app. Pass `null` to
|
||||
* explicitly opt out; omit to default to a `MemoryBlobStore`.
|
||||
*/
|
||||
blobStore?: BlobStore | null;
|
||||
blobOptions?: Pick<BlobRoutesOptions, 'maxBlobBytes'>;
|
||||
} & Pick<InboxRoutesOptions, 'observability' | 'quota' | 'bridgeDeliveryLog'>,
|
||||
): Hono {
|
||||
const store = options.store ?? new MemoryInboxStore();
|
||||
const routesOptions: InboxRoutesOptions = {};
|
||||
if (options.disableRateLimit !== undefined) routesOptions.disableRateLimit = options.disableRateLimit;
|
||||
@@ -61,5 +77,23 @@ export function createInboxServer(options: {
|
||||
if (options.observability !== undefined) routesOptions.observability = options.observability;
|
||||
if (options.quota !== undefined) routesOptions.quota = options.quota;
|
||||
if (options.bridgeDeliveryLog !== undefined) routesOptions.bridgeDeliveryLog = options.bridgeDeliveryLog;
|
||||
return createInboxRoutes(store, options.crypto, routesOptions);
|
||||
|
||||
const inboxApp = createInboxRoutes(store, options.crypto, routesOptions);
|
||||
|
||||
// Compose with the blob primitive unless explicitly disabled. The
|
||||
// blob routes share the same Hono app so a single port serves both.
|
||||
if (options.blobStore === null) return inboxApp;
|
||||
const blobStore = options.blobStore ?? new MemoryBlobStore();
|
||||
const blobRoutesOptions: BlobRoutesOptions = {};
|
||||
if (options.disableRateLimit !== undefined) blobRoutesOptions.disableRateLimit = options.disableRateLimit;
|
||||
if (options.observability !== undefined) blobRoutesOptions.observability = options.observability;
|
||||
if (options.blobOptions?.maxBlobBytes !== undefined) {
|
||||
blobRoutesOptions.maxBlobBytes = options.blobOptions.maxBlobBytes;
|
||||
}
|
||||
const blobApp = createBlobRoutes(blobStore, options.crypto, blobRoutesOptions);
|
||||
|
||||
const composed = new Hono();
|
||||
composed.route('/', inboxApp);
|
||||
composed.route('/', blobApp);
|
||||
return composed;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user