From 9f9e822c6d34dbe47f5c3f520160f1a14346a99d Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Fri, 5 Aug 2022 16:35:56 -0300 Subject: [PATCH] allow skipping signature verification. --- index.d.ts | 1 + package.json | 2 +- relay.js | 9 ++++++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/index.d.ts b/index.d.ts index b67464d..59b8971 100644 --- a/index.d.ts +++ b/index.d.ts @@ -69,6 +69,7 @@ declare type SubscriptionCallback = (event: Event, relay: string) => void; declare type SubscriptionOptions = { cb: SubscriptionCallback, filter: Filter, + skipVerification: boolean // TODO: thread through how `beforeSend` actually works before trying to type it // beforeSend(event: Event): }; diff --git a/package.json b/package.json index 4f5202b..84fc150 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nostr-tools", - "version": "0.23.4", + "version": "0.24.0", "description": "Tools for making a Nostr client.", "repository": { "type": "git", diff --git a/relay.js b/relay.js index fb65cef..d8423b6 100644 --- a/relay.js +++ b/relay.js @@ -18,6 +18,7 @@ export function relayConnect(url, onNotice = () => {}, onError = () => {}) { var ws, resolveOpen, untilOpen, wasClosed var openSubs = {} + var isSetToSkipVerification = {} let attemptNumber = 1 let nextAttemptSeconds = 1 @@ -94,7 +95,7 @@ export function relayConnect(url, onNotice = () => {}, onError = () => {}) { if ( validateEvent(event) && - verifySignature(event) && + (isSetToSkipVerification[channel] || verifySignature(event)) && channels[channel] && matchFilters(openSubs[channel], event) ) { @@ -120,7 +121,7 @@ export function relayConnect(url, onNotice = () => {}, onError = () => {}) { } const sub = ( - {cb, filter, beforeSend}, + {cb, filter, beforeSend, skipVerification}, channel = Math.random().toString().slice(2) ) => { var filters = [] @@ -138,6 +139,7 @@ export function relayConnect(url, onNotice = () => {}, onError = () => {}) { trySend(['REQ', channel, ...filters]) channels[channel] = cb openSubs[channel] = filters + isSetToSkipVerification[channel] = skipVerification const activeCallback = cb const activeFilters = filters @@ -148,10 +150,11 @@ export function relayConnect(url, onNotice = () => {}, onError = () => {}) { cb = activeCallback, filter = activeFilters, beforeSend = activeBeforeSend - }) => sub({cb, filter, beforeSend}, channel), + }) => sub({cb, filter, beforeSend, skipVerification}, channel), unsub: () => { delete openSubs[channel] delete channels[channel] + delete isSetToSkipVerification[channel] trySend(['CLOSE', channel]) } }