mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-09 00:28:51 +00:00
allow skipping signature verification.
This commit is contained in:
1
index.d.ts
vendored
1
index.d.ts
vendored
@@ -69,6 +69,7 @@ declare type SubscriptionCallback = (event: Event, relay: string) => void;
|
|||||||
declare type SubscriptionOptions = {
|
declare type SubscriptionOptions = {
|
||||||
cb: SubscriptionCallback,
|
cb: SubscriptionCallback,
|
||||||
filter: Filter,
|
filter: Filter,
|
||||||
|
skipVerification: boolean
|
||||||
// TODO: thread through how `beforeSend` actually works before trying to type it
|
// TODO: thread through how `beforeSend` actually works before trying to type it
|
||||||
// beforeSend(event: Event):
|
// beforeSend(event: Event):
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "nostr-tools",
|
"name": "nostr-tools",
|
||||||
"version": "0.23.4",
|
"version": "0.24.0",
|
||||||
"description": "Tools for making a Nostr client.",
|
"description": "Tools for making a Nostr client.",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
9
relay.js
9
relay.js
@@ -18,6 +18,7 @@ export function relayConnect(url, onNotice = () => {}, onError = () => {}) {
|
|||||||
|
|
||||||
var ws, resolveOpen, untilOpen, wasClosed
|
var ws, resolveOpen, untilOpen, wasClosed
|
||||||
var openSubs = {}
|
var openSubs = {}
|
||||||
|
var isSetToSkipVerification = {}
|
||||||
let attemptNumber = 1
|
let attemptNumber = 1
|
||||||
let nextAttemptSeconds = 1
|
let nextAttemptSeconds = 1
|
||||||
|
|
||||||
@@ -94,7 +95,7 @@ export function relayConnect(url, onNotice = () => {}, onError = () => {}) {
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
validateEvent(event) &&
|
validateEvent(event) &&
|
||||||
verifySignature(event) &&
|
(isSetToSkipVerification[channel] || verifySignature(event)) &&
|
||||||
channels[channel] &&
|
channels[channel] &&
|
||||||
matchFilters(openSubs[channel], event)
|
matchFilters(openSubs[channel], event)
|
||||||
) {
|
) {
|
||||||
@@ -120,7 +121,7 @@ export function relayConnect(url, onNotice = () => {}, onError = () => {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const sub = (
|
const sub = (
|
||||||
{cb, filter, beforeSend},
|
{cb, filter, beforeSend, skipVerification},
|
||||||
channel = Math.random().toString().slice(2)
|
channel = Math.random().toString().slice(2)
|
||||||
) => {
|
) => {
|
||||||
var filters = []
|
var filters = []
|
||||||
@@ -138,6 +139,7 @@ export function relayConnect(url, onNotice = () => {}, onError = () => {}) {
|
|||||||
trySend(['REQ', channel, ...filters])
|
trySend(['REQ', channel, ...filters])
|
||||||
channels[channel] = cb
|
channels[channel] = cb
|
||||||
openSubs[channel] = filters
|
openSubs[channel] = filters
|
||||||
|
isSetToSkipVerification[channel] = skipVerification
|
||||||
|
|
||||||
const activeCallback = cb
|
const activeCallback = cb
|
||||||
const activeFilters = filters
|
const activeFilters = filters
|
||||||
@@ -148,10 +150,11 @@ export function relayConnect(url, onNotice = () => {}, onError = () => {}) {
|
|||||||
cb = activeCallback,
|
cb = activeCallback,
|
||||||
filter = activeFilters,
|
filter = activeFilters,
|
||||||
beforeSend = activeBeforeSend
|
beforeSend = activeBeforeSend
|
||||||
}) => sub({cb, filter, beforeSend}, channel),
|
}) => sub({cb, filter, beforeSend, skipVerification}, channel),
|
||||||
unsub: () => {
|
unsub: () => {
|
||||||
delete openSubs[channel]
|
delete openSubs[channel]
|
||||||
delete channels[channel]
|
delete channels[channel]
|
||||||
|
delete isSetToSkipVerification[channel]
|
||||||
trySend(['CLOSE', channel])
|
trySend(['CLOSE', channel])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user