|
1 | 1 | import { Event, ExpiringEvent } from '../@types/event' |
2 | 2 | import { EventRateLimit, FeeSchedule, Settings } from '../@types/settings' |
3 | | -import { getEventExpiration, getEventProofOfWork, getPubkeyProofOfWork, isEventIdValid, isEventKindOrRangeMatch, isEventSignatureValid, isExpiredEvent } from '../utils/event' |
| 3 | +import { getEventExpiration, getEventProofOfWork, getPubkeyProofOfWork, getPublicKey, getRelayPrivateKey, isEventIdValid, isEventKindOrRangeMatch, isEventSignatureValid, isExpiredEvent } from '../utils/event' |
4 | 4 | import { IEventStrategy, IMessageHandler } from '../@types/message-handlers' |
5 | 5 | import { ContextMetadataKey } from '../constants/base' |
6 | 6 | import { createCommandResult } from '../utils/messages' |
@@ -79,7 +79,15 @@ export class EventMessageHandler implements IMessageHandler { |
79 | 79 | } |
80 | 80 | } |
81 | 81 |
|
| 82 | + protected getRelayPublicKey(): string { |
| 83 | + const relayPrivkey = getRelayPrivateKey(this.settings().info.relay_url) |
| 84 | + return getPublicKey(relayPrivkey) |
| 85 | + } |
| 86 | + |
82 | 87 | protected canAcceptEvent(event: Event): string | undefined { |
| 88 | + if (this.getRelayPublicKey() === event.pubkey) { |
| 89 | + return |
| 90 | + } |
83 | 91 | const now = Math.floor(Date.now()/1000) |
84 | 92 |
|
85 | 93 | const limits = this.settings().limits?.event ?? {} |
@@ -185,6 +193,10 @@ export class EventMessageHandler implements IMessageHandler { |
185 | 193 | } |
186 | 194 |
|
187 | 195 | protected async isRateLimited(event: Event): Promise<boolean> { |
| 196 | + if (this.getRelayPublicKey() === event.pubkey) { |
| 197 | + return false |
| 198 | + } |
| 199 | + |
188 | 200 | const { whitelists, rateLimits } = this.settings().limits?.event ?? {} |
189 | 201 | if (!rateLimits || !rateLimits.length) { |
190 | 202 | return false |
@@ -249,6 +261,10 @@ export class EventMessageHandler implements IMessageHandler { |
249 | 261 | return |
250 | 262 | } |
251 | 263 |
|
| 264 | + if (this.getRelayPublicKey() === event.pubkey) { |
| 265 | + return |
| 266 | + } |
| 267 | + |
252 | 268 | const isApplicableFee = (feeSchedule: FeeSchedule) => |
253 | 269 | feeSchedule.enabled |
254 | 270 | && !feeSchedule.whitelists?.pubkeys?.some((prefix) => event.pubkey.startsWith(prefix)) |
|
0 commit comments