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;