Formatting

This commit is contained in:
2026-08-03 03:40:57 +00:00
parent 97d4422b8f
commit c9845d0f28
6 changed files with 214 additions and 246 deletions
+1 -1
View File
@@ -41,7 +41,7 @@ export class App {
const http = new HttpTransportRouter(router, debug);
const ws = new WsTransportRouter(router, debug, config.server.maxRequestBodyBytes);
const host = new ServerHost(config, debug, [http, ws]);
const host = new ServerHost(config, debug, [ http, ws ]);
return new App(host, database);
}
+7 -7
View File
@@ -42,7 +42,7 @@ const resourceIdsSchema = z.object({
resourceId: z
.array(z.string().min(1))
.min(1, 'At least one resourceId is required')
.transform((ids) => [...new Set(ids)]),
.transform((ids) => [ ...new Set(ids) ]),
});
type WriteResource = z.infer<typeof writeResource>;
@@ -95,7 +95,7 @@ export class DataRoute implements RouteModule {
const resourceIds = this.getResourceIds(stream);
// Remove duplicates.
const uniqueIds = [...new Set(resourceIds)];
const uniqueIds = [ ...new Set(resourceIds) ];
// If there are no resource ids, return an empty array.
if (uniqueIds.length === 0) {
@@ -107,7 +107,7 @@ export class DataRoute implements RouteModule {
// Read the data from the database.
const rows = await this.database.db
.selectFrom('resource_data')
.select(['resource_id', 'public_key', 'blob', 'timestamp'])
.select([ 'resource_id', 'public_key', 'blob', 'timestamp' ])
.where('resource_id', 'in', uniqueIds)
.orderBy('timestamp', 'asc')
.execute();
@@ -155,11 +155,10 @@ export class DataRoute implements RouteModule {
timestamp,
})
.onConflict((oc) =>
oc.columns(['resource_id', 'public_key']).doUpdateSet({
oc.columns([ 'resource_id', 'public_key' ]).doUpdateSet({
blob,
timestamp,
}),
)
}))
.execute();
}
});
@@ -276,7 +275,8 @@ export class DataRoute implements RouteModule {
const signature = hexToBin(signatureHex);
// Create a SHA-256 hash of the payload.
const messageHash = createHash('sha256').update(payload).digest();
const messageHash = createHash('sha256').update(payload)
.digest();
// Low-S normalization rejects malleable signature encodings.
return secp256k1.verifySignatureDERLowS(signature, publicKey, messageHash);
+4 -5
View File
@@ -20,7 +20,8 @@ const WS_ROUTE = '/ws';
// Strict validation prevents legacy or protocol-specific fields reaching routes.
const wsRequestSchema = z
.object({
id: z.string().min(1).optional(),
id: z.string().min(1)
.optional(),
path: z.string().min(1),
body: z.unknown().optional(),
})
@@ -178,13 +179,11 @@ export class WsTransportRouter implements UpgradeTransportRouter {
* @param error - Failure to normalize into the public error shape.
*/
private sendError(ws: WSContext, requestId: string | undefined, error: unknown): void {
ws.send(
toExtendedJson({
ws.send(toExtendedJson({
...(requestId === undefined ? {} : { id: requestId }),
type: 'error',
...normalizePublicError(error),
}),
);
}));
}
/**