release(v4.0.0): Shade GA — V3.x consolidation + audit prep
Some checks failed
Test / test (push) Has been cancelled
Cross-platform vectors / TypeScript vectors (bun) (push) Has been cancelled
Cross-platform vectors / Kotlin vectors (gradle) (push) Has been cancelled
Docker build and publish / docker (push) Has been cancelled
Publish / publish (push) Has been cancelled
Some checks failed
Test / test (push) Has been cancelled
Cross-platform vectors / TypeScript vectors (bun) (push) Has been cancelled
Cross-platform vectors / Kotlin vectors (gradle) (push) Has been cancelled
Docker build and publish / docker (push) Has been cancelled
Publish / publish (push) Has been cancelled
V3.1 → V3.12 consolidated and tagged for the first GA release. Wire format unchanged from 0.4.x — 4.0 peers interoperate with 0.4.x peers byte-for-byte. The version bump is semantic: audit-cycle complete, opt-in surface fully exposed, threat model refreshed for every new surface. Highlights: - All 24 @shade/* packages bumped to 4.0.0 in lockstep. - CHANGELOG 4.0.0 section is the canonical manifest of what landed. - THREAT-MODEL extended (§10 fingerprint gates, §11 WebRTC P2P, §12 Web-Worker boundary) + residual-risks table refreshed. - OpenAPI now covers all 27 routes: prekey, transfer, KT, inbox, bridge, observer, /metrics, /healthz, /ready. - MIGRATION 0.3.x → 4.0 documented + smoke-tested against shade migrate-storage on a real SQLite DB. - docs/audit/REVIEW-BUNDLE.md + SCOPE.md ready for external reviewer. - scripts/soak.ts harness for the GA-stable 2-week soak window. - All V*.md plans archived under docs/archive/ with Status: Done. - Voice/Video carved out into V5.0; 4.0 audit focuses on the frozen non-realtime stack. Tests: TS 1000/1000 + Kotlin 11/11 cross-platform vectors green. Docker: gt.zyon.no/stian/shade-prekey:4.0.0 builds and reports version 4.0.0 on /health. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,16 @@ import type { PrekeyStore } from './store.js';
|
||||
import { verifyPayload, validateAddress } from './auth.js';
|
||||
import { RateLimiter, MemoryRateLimitStore, REGISTER_LIMIT, FETCH_LIMIT, REPLENISH_LIMIT, DELETE_LIMIT } from './rate-limit.js';
|
||||
import { PrekeyServerEvents, shortHash } from './events.js';
|
||||
import {
|
||||
ATTR_ERROR_CODE,
|
||||
ATTR_HTTP_STATUS,
|
||||
ATTR_ROUTE,
|
||||
NOOP_HOOK,
|
||||
type ObservabilityHook,
|
||||
} from '@shade/observability';
|
||||
import type { KeyTransparencyService } from './kt-integration.js';
|
||||
import { encodeProofForWire, encodeSthForWire } from './kt-integration.js';
|
||||
import { createKTRoutes } from './kt-routes.js';
|
||||
|
||||
/** Max POST body size in bytes (64KB) */
|
||||
const MAX_BODY_SIZE = 64 * 1024;
|
||||
@@ -26,6 +36,22 @@ export interface PrekeyRoutesOptions {
|
||||
disableRateLimit?: boolean;
|
||||
/** Optional event emitter for observability. */
|
||||
events?: PrekeyServerEvents;
|
||||
/**
|
||||
* Optional OTel observability hook. When supplied (and the runtime gate
|
||||
* is on), each request gets a `shade.prekey.<route>` span with route
|
||||
* + HTTP-status attributes. PII-safe: never logs the address path
|
||||
* parameter or client IP.
|
||||
*/
|
||||
observability?: ObservabilityHook;
|
||||
/**
|
||||
* Optional Key-Transparency service (V3.12). When provided:
|
||||
* - Every `register` and `delete` mutation is committed to the log.
|
||||
* - `GET /v1/keys/bundle/:address` includes a `ktProof` field.
|
||||
* - `/v1/kt/*` routes are mounted (latest STH, historical STHs,
|
||||
* consistency proofs, log_id pinning info).
|
||||
* When absent, the server is byte-compatible with pre-V3.12 clients.
|
||||
*/
|
||||
keyTransparency?: KeyTransparencyService;
|
||||
}
|
||||
|
||||
export function createPrekeyRoutes(
|
||||
@@ -35,6 +61,35 @@ export function createPrekeyRoutes(
|
||||
): Hono {
|
||||
const app = new Hono();
|
||||
const events = options.events;
|
||||
const observability = options.observability ?? NOOP_HOOK;
|
||||
const kt = options.keyTransparency;
|
||||
|
||||
// Per-request span middleware — runs first so it covers handlers AND
|
||||
// the global error handler. Span name is the route template (e.g.
|
||||
// `/v1/keys/bundle/:address`), so cardinality stays bounded and the
|
||||
// address itself never enters span data.
|
||||
app.use('*', async (c, next) => {
|
||||
const route = c.req.routePath ?? c.req.path ?? '<unknown>';
|
||||
const span = observability.startSpan('shade.prekey.request', {
|
||||
[ATTR_ROUTE]: route,
|
||||
});
|
||||
try {
|
||||
await next();
|
||||
span.setAttribute(ATTR_HTTP_STATUS, c.res.status);
|
||||
span.setStatus(c.res.status >= 500 ? 'error' : 'ok');
|
||||
} catch (err) {
|
||||
const code =
|
||||
err instanceof ShadeError
|
||||
? err.code ?? 'SHADE_ERROR'
|
||||
: 'SHADE_INTERNAL';
|
||||
span.setAttribute(ATTR_ERROR_CODE, code);
|
||||
span.recordException(err);
|
||||
span.setStatus('error', code);
|
||||
throw err;
|
||||
} finally {
|
||||
span.end();
|
||||
}
|
||||
});
|
||||
|
||||
// Rate limiters (one per route, per IP or per identity)
|
||||
const rlStore = new MemoryRateLimitStore();
|
||||
@@ -115,6 +170,21 @@ export function createPrekeyRoutes(
|
||||
await store.saveOneTimePreKeys(addr, keys);
|
||||
}
|
||||
|
||||
// Commit to KT log (if enabled). The bundle covered by the commitment
|
||||
// is { signing_key, dh_key, signed_prekey } — one-time prekeys are
|
||||
// intentionally excluded so OTP rotation doesn't churn the log.
|
||||
if (kt) {
|
||||
await kt.recordRegister(addr, {
|
||||
identitySigningKey: signingKey,
|
||||
identityDHKey: dhKey,
|
||||
signedPreKey: {
|
||||
keyId: signedPreKey.keyId,
|
||||
publicKey: b64ToBytes(signedPreKey.publicKey),
|
||||
signature: b64ToBytes(signedPreKey.signature),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (events) {
|
||||
const hash = await shortHash(signingKey);
|
||||
events.emit('server.identity_registered', { address: addr, identityKeyHash: hash });
|
||||
@@ -130,6 +200,33 @@ export function createPrekeyRoutes(
|
||||
|
||||
const identity = await store.getIdentity(address);
|
||||
if (!identity) {
|
||||
// KT-enabled: pin the negative answer to a tree state. If the
|
||||
// address has been tombstoned we serve the tombstone (inclusion)
|
||||
// proof; otherwise an absence proof.
|
||||
if (kt) {
|
||||
const inclusion = await kt.buildBundleInclusion(address);
|
||||
if (inclusion) {
|
||||
return c.json(
|
||||
{
|
||||
error: 'Address not found',
|
||||
code: 'SHADE_NOT_FOUND',
|
||||
ktProof: encodeProofForWire(inclusion),
|
||||
},
|
||||
404,
|
||||
);
|
||||
}
|
||||
const absence = await kt.buildAbsence(address);
|
||||
if (absence) {
|
||||
return c.json(
|
||||
{
|
||||
error: 'Address not found',
|
||||
code: 'SHADE_NOT_FOUND',
|
||||
ktProof: encodeProofForWire(absence),
|
||||
},
|
||||
404,
|
||||
);
|
||||
}
|
||||
}
|
||||
return c.json({ error: 'Address not found', code: 'SHADE_NOT_FOUND' }, 404);
|
||||
}
|
||||
|
||||
@@ -157,6 +254,19 @@ export function createPrekeyRoutes(
|
||||
};
|
||||
}
|
||||
|
||||
if (kt) {
|
||||
const proof = await kt.buildBundleInclusion(address);
|
||||
if (proof) {
|
||||
bundle.ktProof = encodeProofForWire(proof);
|
||||
} else {
|
||||
// No live entry in the index — fall back to STH so client at
|
||||
// least sees a fresh tree-head, then surfaces "no proof available"
|
||||
// as a soft warning.
|
||||
const sth = await kt.getLatestSTH();
|
||||
bundle.ktSth = encodeSthForWire(sth);
|
||||
}
|
||||
}
|
||||
|
||||
// Update activity so stale cleanup doesn't purge active addresses
|
||||
await store.touchIdentity(address);
|
||||
|
||||
@@ -228,10 +338,17 @@ export function createPrekeyRoutes(
|
||||
await verifyPayload(crypto, identity.identitySigningKey, { ...body, address });
|
||||
|
||||
await store.deleteAll(address);
|
||||
if (kt) {
|
||||
await kt.recordDelete(address);
|
||||
}
|
||||
events?.emit('server.identity_deleted', { address });
|
||||
return c.json({ ok: true });
|
||||
});
|
||||
|
||||
if (kt) {
|
||||
app.route('/v1/kt', createKTRoutes(kt));
|
||||
}
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user