allow skipping signature verification.

This commit is contained in:
fiatjaf
2022-08-05 16:35:56 -03:00
parent 821a8f7895
commit 9f9e822c6d
3 changed files with 8 additions and 4 deletions

1
index.d.ts vendored
View File

@@ -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):
};

View File

@@ -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",

View File

@@ -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])
}
}