Allow opting out of signature validation
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "paravel",
|
"name": "paravel",
|
||||||
"version": "0.4.12",
|
"version": "0.4.13",
|
||||||
"description": "Yet another toolkit for nostr",
|
"description": "Yet another toolkit for nostr",
|
||||||
"author": "hodlbod",
|
"author": "hodlbod",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
+10
-1
@@ -10,6 +10,7 @@ export type SubscriptionOpts = {
|
|||||||
timeout?: number
|
timeout?: number
|
||||||
closeOnEose?: boolean
|
closeOnEose?: boolean
|
||||||
hasSeen?: (e: Event, url: string) => boolean
|
hasSeen?: (e: Event, url: string) => boolean
|
||||||
|
shouldValidate?: (e: Event, url: string) => boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Subscription extends EventEmitter {
|
export class Subscription extends EventEmitter {
|
||||||
@@ -69,13 +70,21 @@ export class Subscription extends EventEmitter {
|
|||||||
return false
|
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) => {
|
onEvent = (url: string, event: Event) => {
|
||||||
// If we've seen this event, don't re-validate
|
// If we've seen this event, don't re-validate
|
||||||
// Otherwise, check the signature and filters
|
// Otherwise, check the signature and filters
|
||||||
if (this.hasSeen(event, url)) {
|
if (this.hasSeen(event, url)) {
|
||||||
this.emit("duplicate", event, url)
|
this.emit("duplicate", event, url)
|
||||||
} else {
|
} else {
|
||||||
if (!hasValidSignature(event)) {
|
if (!this.hasValidSignature(event, url)) {
|
||||||
this.emit("invalid-signature", event, url)
|
this.emit("invalid-signature", event, url)
|
||||||
} else if (!matchFilters(this.opts.filters, event)) {
|
} else if (!matchFilters(this.opts.filters, event)) {
|
||||||
this.emit("failed-filter", event, url)
|
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
|
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()
|
getReply = (type = null) => this.replies(type).values().first()
|
||||||
|
|
||||||
getRoot = (type = null) => this.roots(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()
|
getReplyHints = (type = null) => this.replies(type).relays().all()
|
||||||
|
|
||||||
getRootHints = (type = null) => this.roots(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