validate events on receive
This commit is contained in:
@ -4,6 +4,7 @@ import { getPublicKey, sha256, unixNow } from "@snort/shared";
|
||||
|
||||
import { EventKind, HexKey, NostrEvent, NotSignedNostrEvent } from ".";
|
||||
import { minePow } from "./pow-util";
|
||||
import { findTag } from "./utils";
|
||||
|
||||
export interface Tag {
|
||||
key: string;
|
||||
@ -19,6 +20,12 @@ export interface Thread {
|
||||
pubKeys: Array<HexKey>;
|
||||
}
|
||||
|
||||
export const enum EventType {
|
||||
Regular,
|
||||
Replaceable,
|
||||
ParameterizedReplaceable,
|
||||
}
|
||||
|
||||
export abstract class EventExt {
|
||||
/**
|
||||
* Get the pub key of the creator of this event NIP-26
|
||||
@ -149,4 +156,25 @@ export abstract class EventExt {
|
||||
e.pubkey ??= "";
|
||||
e.sig ??= "";
|
||||
}
|
||||
|
||||
static getType(kind: number) {
|
||||
const legacyReplaceable = [0, 3, 41];
|
||||
if (kind >= 30_000 && kind < 40_000) {
|
||||
return EventType.ParameterizedReplaceable;
|
||||
} else if (kind >= 10_000 && kind < 20_000) {
|
||||
return EventType.Replaceable;
|
||||
} else if (legacyReplaceable.includes(kind)) {
|
||||
return EventType.Replaceable;
|
||||
} else {
|
||||
return EventType.Regular;
|
||||
}
|
||||
}
|
||||
|
||||
static isValid(ev: NostrEvent) {
|
||||
const type = EventExt.getType(ev.kind);
|
||||
if (type === EventType.ParameterizedReplaceable) {
|
||||
if (!findTag(ev, "d")) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user