feat: make sig checks optional

This commit is contained in:
2023-10-13 16:34:31 +01:00
parent 87bb9dafeb
commit 93e8e0bbae
51 changed files with 171 additions and 240 deletions

View File

@ -176,6 +176,6 @@ export abstract class EventExt {
if (type === EventType.ParameterizedReplaceable) {
if (!findTag(ev, "d")) return false;
}
return EventExt.verify(ev);
return true;
}
}

View File

@ -41,6 +41,11 @@ export * from "./cache/user-metadata";
export * from "./cache/relay-metric";
export interface SystemInterface {
/**
* Check event signatures (reccomended)
*/
checkSigs: boolean;
/**
* Handler function for NIP-42
*/

View File

@ -81,6 +81,11 @@ export class NostrSystem extends ExternalStore<SystemSnapshot> implements System
*/
#queryOptimizer: QueryOptimizer;
/**
* Check event signatures (reccomended)
*/
checkSigs: boolean;
constructor(props: {
authHandler?: AuthHandler;
relayCache?: FeedCache<UsersRelays>;
@ -89,6 +94,7 @@ export class NostrSystem extends ExternalStore<SystemSnapshot> implements System
eventsCache?: FeedCache<NostrEvent>;
queryOptimizer?: QueryOptimizer;
db?: SnortSystemDb;
checkSigs?: boolean;
}) {
super();
this.#handleAuth = props.authHandler;
@ -100,6 +106,7 @@ export class NostrSystem extends ExternalStore<SystemSnapshot> implements System
this.#profileLoader = new ProfileLoaderService(this, this.#profileCache);
this.#relayMetrics = new RelayMetricHandler(this.#relayMetricsCache);
this.checkSigs = props.checkSigs ?? true;
this.#cleanup();
}
@ -183,6 +190,10 @@ export class NostrSystem extends ExternalStore<SystemSnapshot> implements System
this.#log("Rejecting invalid event %O", ev);
return;
}
if (this.checkSigs && !EventExt.verify(ev)) {
this.#log("Invalid sig %O", ev);
return;
}
for (const [, v] of this.Queries) {
v.handleEvent(sub, ev);