diff --git a/package.json b/package.json index f348a20..23939c3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "paravel", - "version": "0.4.12", + "version": "0.4.13", "description": "Yet another toolkit for nostr", "author": "hodlbod", "license": "MIT", diff --git a/src/Subscription.ts b/src/Subscription.ts index 1da5024..edb8b5f 100644 --- a/src/Subscription.ts +++ b/src/Subscription.ts @@ -10,6 +10,7 @@ export type SubscriptionOpts = { timeout?: number closeOnEose?: boolean hasSeen?: (e: Event, url: string) => boolean + shouldValidate?: (e: Event, url: string) => boolean } export class Subscription extends EventEmitter { @@ -69,13 +70,21 @@ export class Subscription extends EventEmitter { return false } + hasValidSignature = (event: Event, url: string) => { + if (this.opts.shouldValidate && !this.opts.shouldValidate(event, url)) { + return true + } + + return hasValidSignature(event) + } + onEvent = (url: string, event: Event) => { // If we've seen this event, don't re-validate // Otherwise, check the signature and filters if (this.hasSeen(event, url)) { this.emit("duplicate", event, url) } else { - if (!hasValidSignature(event)) { + if (!this.hasValidSignature(event, url)) { this.emit("invalid-signature", event, url) } else if (!matchFilters(this.opts.filters, event)) { this.emit("failed-filter", event, url) diff --git a/src/util/nostr.ts b/src/util/nostr.ts index 34fe580..4e5a053 100644 --- a/src/util/nostr.ts +++ b/src/util/nostr.ts @@ -217,6 +217,8 @@ export class Tags extends Fluent { replies = (type = null) => this.getAncestors(type).replies + communities = () => this.type("a").values().filter(a => a.startsWith('34550:')) + getReply = (type = null) => this.replies(type).values().first() getRoot = (type = null) => this.roots(type).values().first() @@ -224,8 +226,6 @@ export class Tags extends Fluent { getReplyHints = (type = null) => this.replies(type).relays().all() getRootHints = (type = null) => this.roots(type).relays().all() - - communities = () => this.type("a").values().filter(a => a.startsWith('34550:')) } // ===========================================================================