MCPcopy Index your code
hub / github.com/cameri/nostream / isEventValid

Method isEventValid

src/handlers/event-message-handler.ts:227–252  ·  view source on GitHub ↗
(event: Event)

Source from the content-addressed store, hash-verified

225 }
226
227 protected async isEventValid(event: Event): Promise<string | undefined> {
228 if (!(await isEventIdValid(event))) {
229 return 'invalid: event id does not match'
230 }
231 if (!(await isEventSignatureValid(event))) {
232 return 'invalid: event signature verification failed'
233 }
234
235 if (event.kind === EventKinds.REQUEST_TO_VANISH && !isRequestToVanishEvent(event, this.settings().info.relay_url)) {
236 return 'invalid: request to vanish relay tag invalid'
237 }
238
239 // NIP-17: kind 13 (Seal) and kind 14 (Direct Message) are inner events that
240 // must never be published directly to a relay. They are encrypted inside a
241 // kind 1059 Gift Wrap (NIP-59) before being sent here.
242 // Marmot MIP-02: kind 444 (Welcome rumor) is similarly an inner event that
243 // must only be delivered inside a kind 1059 gift wrap.
244 if (isSealEvent(event) || isDirectMessageEvent(event) || isFileMessageEvent(event) || isWelcomeRumorEvent(event)) {
245 return `blocked: kind ${event.kind} events must not be published directly; wrap them in a kind 1059 gift wrap`
246 }
247
248 // NIP-42: auth events must use the AUTH message type
249 if (event.kind === EventKinds.AUTH) {
250 return 'invalid: auth events must be sent using the AUTH message type'
251 }
252 }
253
254 protected async isBlockedByRequestToVanish(event: Event): Promise<string | undefined> {
255 if (isRequestToVanishEvent(event)) {

Callers 2

handleMessageMethod · 0.95

Calls 7

isEventIdValidFunction · 0.90
isEventSignatureValidFunction · 0.90
isRequestToVanishEventFunction · 0.90
isSealEventFunction · 0.90
isDirectMessageEventFunction · 0.90
isFileMessageEventFunction · 0.90
isWelcomeRumorEventFunction · 0.90

Tested by

no test coverage detected