From 817519c1321fd617ef1288e72190de852c3711ea Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 26 Mar 2023 15:43:48 -0500 Subject: [PATCH] pubkeyBanPolicy: support iterables --- src/policies/pubkey-ban-policy.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/policies/pubkey-ban-policy.ts b/src/policies/pubkey-ban-policy.ts index 691a7ba..3fb68ba 100644 --- a/src/policies/pubkey-ban-policy.ts +++ b/src/policies/pubkey-ban-policy.ts @@ -1,8 +1,18 @@ import { Policy } from '../types.ts'; -/** Ban individual pubkeys from publishing events to the relay. */ -const pubkeyPolicy: Policy = ({ event: { id, pubkey } }, pubkeys = []) => { - const isMatch = pubkeys.includes(pubkey); +/** + * Ban individual pubkeys from publishing events to the relay. + * Pass an array of pubkeys or an iterable, making it efficient to load pubkeys from a large file. + */ +const pubkeyBanPolicy: Policy> = ({ event: { id, pubkey } }, pubkeys = []) => { + let isMatch = false; + + for (const p of pubkeys) { + if (p === pubkey) { + isMatch = true; + break; + } + } if (isMatch) { return { @@ -19,4 +29,4 @@ const pubkeyPolicy: Policy = ({ event: { id, pubkey } }, pubkeys = []) }; }; -export default pubkeyPolicy; +export default pubkeyBanPolicy;