mirror of
https://github.com/hanzoai/sign.git
synced 2026-10-21 01:21:51 +00:00
The socket the app's pages call over (/zap) opened only for a session, so a recipient signing by their link, who has no account, could not reach the routes that sign a field or complete a document: every field they clicked failed with "An error occurred while signing the field". tRPC had served those as public procedures; the port to ZAP kept their bodies and lost the door. A connection from the app's own pages with no session now opens as anonymous and reaches only the routes tRPC served publicly, each authorised by the token it carries; every other route answers it 401 before its handler runs. The operation API still refuses a request without a token.
34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
// esign ZAP RPC — server entry.
|
|
//
|
|
// `serveZap(httpServer)` attaches the ZAP-over-WebSocket RPC endpoint to the
|
|
// Remix Node http.Server (one line, one port — same server that serves the
|
|
// app). This is the replacement for mounting the tRPC HTTP handler. Auth runs
|
|
// at the WS upgrade via the esign MintCap; every decoded call is routed by the
|
|
// dispatcher over the registered route map.
|
|
import { type ServeHandle, serve } from '@zap-proto/web/server';
|
|
import type { Server as HttpServer } from 'node:http';
|
|
|
|
import { ZAP_PATH } from '../runtime/path';
|
|
import { makeDispatcher } from './dispatch';
|
|
import { makeMintCap } from './mint';
|
|
import { publicRoutes, zapRoutes } from './routes';
|
|
|
|
export { ZAP_PATH };
|
|
|
|
/** Attach the esign ZAP RPC endpoint to an existing Node http.Server. */
|
|
export function serveZap(
|
|
httpServer: HttpServer,
|
|
opts: { path?: string; onError?: (err: unknown) => void } = {},
|
|
): ServeHandle {
|
|
return serve(httpServer, {
|
|
path: opts.path ?? ZAP_PATH,
|
|
mintCap: makeMintCap('app'),
|
|
rootCap: makeDispatcher(zapRoutes, publicRoutes),
|
|
onError: opts.onError,
|
|
});
|
|
}
|
|
|
|
export { zapRoutes, migratedRoutes, publicRoutes } from './routes';
|
|
export type { AnonymousZapContext, ZapConnectionContext, ZapContext } from './context';
|
|
export type { ZapHandler, ZapRouteMap } from './dispatch';
|