-
Notifications
You must be signed in to change notification settings - Fork 234
add NIP-62 vanish event support #418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { createCommandResult } from '../../utils/messages' | ||
| import { createLogger } from '../../factories/logger-factory' | ||
| import { Event } from '../../@types/event' | ||
| import { EventKinds } from '../../constants/base' | ||
| import { IEventRepository } from '../../@types/repositories' | ||
| import { IEventStrategy } from '../../@types/message-handlers' | ||
| import { IWebSocketAdapter } from '../../@types/adapters' | ||
| import { WebSocketAdapterEvent } from '../../constants/adapter' | ||
|
|
||
| const debug = createLogger('vanish-event-strategy') | ||
|
|
||
| export class VanishEventStrategy implements IEventStrategy<Event, Promise<void>> { | ||
| public constructor( | ||
| private readonly webSocket: IWebSocketAdapter, | ||
| private readonly eventRepository: IEventRepository, | ||
| ) {} | ||
|
|
||
| public async execute(event: Event): Promise<void> { | ||
| debug('received request to vanish event: %o', event) | ||
|
|
||
| await this.eventRepository.deleteByPubkeyExceptKinds( | ||
| event.pubkey, | ||
| [EventKinds.REQUEST_TO_VANISH], | ||
| ) | ||
|
|
||
| const count = await this.eventRepository.create(event) | ||
|
|
||
| this.webSocket.emit( | ||
| WebSocketAdapterEvent.Message, | ||
| createCommandResult(event.id, true, count ? '' : 'duplicate:') | ||
| ) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,9 @@ | ||
| import * as secp256k1 from '@noble/secp256k1' | ||
|
|
||
| import { ALL_RELAYS, EventKinds, EventTags } from '../constants/base' | ||
| import { applySpec, pipe, prop } from 'ramda' | ||
| import { CanonicalEvent, DBEvent, Event, UnidentifiedEvent, UnsignedEvent } from '../@types/event' | ||
| import { createCipheriv, getRandomValues } from 'crypto' | ||
| import { EventId, Pubkey, Tag } from '../@types/base' | ||
| import { EventKinds, EventTags } from '../constants/base' | ||
|
|
||
| import cluster from 'cluster' | ||
| import { deriveFromSecret } from './secret' | ||
| import { EventKindsRange } from '../@types/settings' | ||
|
|
@@ -227,6 +225,18 @@ export const isDeleteEvent = (event: Event): boolean => { | |
| return event.kind === EventKinds.DELETE | ||
| } | ||
|
|
||
| export const isRequestToVanishEvent = (event: Event): boolean => { | ||
| return event.kind === EventKinds.REQUEST_TO_VANISH | ||
| } | ||
|
|
||
| export const isValidRequestToVanishEvent = (event: Event, relayUrl: string): boolean => { | ||
| const relayTags = event.tags | ||
| .filter((tag) => tag.length >= 2 && tag[0] === EventTags.Relay) | ||
| .map((tag) => tag[1]) | ||
|
|
||
| return relayTags.length > 0 && relayTags.every((relay) => relay === relayUrl || relay === ALL_RELAYS) | ||
| } | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this missing the kind number check?
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need two functions? I think we just need 1 combining these two.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes , we can combine these two to make single function to validate eligibility.If you want I can make the changes update the tests according to it
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vikashsiwach Let's merge them please, having two functions can lead to confusion on which one is right one to use. |
||
|
|
||
| export const isExpiredEvent = (event: Event): boolean => { | ||
| if (!event.tags.length) { | ||
| return false | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are likely better off adding a column to the users table. However, I think I am okay with this approach for now. Optimizing this to use the users table can be a separate issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right , a table flag will would be better for long term optimization. I used this event based check to stay scoped to NIP-62 behavior. We can create a follow up issue for this if you want.