Allow opting out of signature validation
This commit is contained in:
+10
-1
@@ -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)
|
||||
|
||||
+2
-2
@@ -217,6 +217,8 @@ export class Tags extends Fluent<string[]> {
|
||||
|
||||
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<string[]> {
|
||||
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:'))
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
Reference in New Issue
Block a user