@@ -4,6 +4,7 @@ import { path, pathEq } from 'ramda'
44import { createSettings } from '../../factories/settings-factory'
55import { escapeHtml } from '../../utils/html'
66import { FeeSchedule } from '../../@types/settings'
7+ import { DEFAULT_FILTER_LIMIT } from '../../constants/base'
78import { fromBech32 } from '../../utils/transform'
89import { getTemplate } from '../../utils/template-cache'
910import packageJson from '../../../package.json'
@@ -13,26 +14,44 @@ export const rootRequestHandler = (request: Request, response: Response, next: N
1314
1415 if ( accepts ( request ) . type ( [ 'application/nostr+json' ] ) ) {
1516 const {
16- info : { name, description, pubkey : rawPubkey , contact, relay_url } ,
17+ info : { name, description, banner , icon , pubkey : rawPubkey , self : rawSelf , contact, relay_url, terms_of_service } ,
1718 } = settings
1819
1920 const paymentsUrl = new URL ( relay_url )
2021 paymentsUrl . protocol = paymentsUrl . protocol === 'wss:' ? 'https:' : 'http:'
2122 paymentsUrl . pathname = '/invoices'
2223
2324 const content = settings . limits ?. event ?. content
25+ const eventLimits = settings . limits ?. event
26+ const createdAtLimits = eventLimits ?. createdAt
27+ const hasAdmissionRestriction =
28+ settings . payments ?. enabled === true &&
29+ Boolean ( settings . payments ?. feeSchedules ?. admission ?. some ( ( feeSchedule ) => feeSchedule . enabled ) )
30+ const hasWriteRestriction =
31+ hasAdmissionRestriction ||
32+ ( eventLimits ?. eventId ?. minLeadingZeroBits ?? 0 ) > 0 ||
33+ ( eventLimits ?. pubkey ?. minLeadingZeroBits ?? 0 ) > 0 ||
34+ ( eventLimits ?. pubkey ?. whitelist ?. length ?? 0 ) > 0 ||
35+ ( eventLimits ?. pubkey ?. blacklist ?. length ?? 0 ) > 0 ||
36+ ( eventLimits ?. kind ?. whitelist ?. length ?? 0 ) > 0 ||
37+ ( eventLimits ?. kind ?. blacklist ?. length ?? 0 ) > 0
2438
2539 const pubkey = rawPubkey . startsWith ( 'npub1' ) ? fromBech32 ( rawPubkey ) : rawPubkey
40+ const self = rawSelf ?. startsWith ( 'npub1' ) ? fromBech32 ( rawSelf ) : rawSelf
2641
2742 const relayInformationDocument = {
2843 name,
2944 description,
45+ ...( banner !== undefined ? { banner } : { } ) ,
46+ ...( icon !== undefined ? { icon } : { } ) ,
3047 pubkey,
48+ ...( self !== undefined ? { self } : { } ) ,
3149 contact,
3250 supported_nips : packageJson . supportedNips ,
3351 supported_nip_extensions : packageJson . supportedNipExtensions ,
3452 software : packageJson . repository . url ,
3553 version : packageJson . version ,
54+ ...( terms_of_service !== undefined ? { terms_of_service } : { } ) ,
3655 limitation : {
3756 max_message_length : settings . network . maxPayloadSize ,
3857 max_subscriptions : settings . limits ?. client ?. subscription ?. maxSubscriptions ,
@@ -44,9 +63,13 @@ export const rootRequestHandler = (request: Request, response: Response, next: N
4463 max_content_length : Array . isArray ( content )
4564 ? content [ 0 ] . maxLength // best guess since we have per-kind limits
4665 : content ?. maxLength ,
47- min_pow_difficulty : settings . limits ?. event ?. eventId ?. minLeadingZeroBits ,
66+ min_pow_difficulty : eventLimits ?. eventId ?. minLeadingZeroBits ,
4867 auth_required : false ,
4968 payment_required : settings . payments ?. enabled ,
69+ created_at_lower_limit : createdAtLimits ?. maxNegativeDelta ,
70+ created_at_upper_limit : createdAtLimits ?. maxPositiveDelta ,
71+ default_limit : DEFAULT_FILTER_LIMIT ,
72+ restricted_writes : hasWriteRestriction ,
5073 } ,
5174 payments_url : paymentsUrl . toString ( ) ,
5275 fees : Object . getOwnPropertyNames ( settings . payments . feeSchedules ) . reduce (
@@ -68,6 +91,8 @@ export const rootRequestHandler = (request: Request, response: Response, next: N
6891 response
6992 . setHeader ( 'content-type' , 'application/nostr+json' )
7093 . setHeader ( 'access-control-allow-origin' , '*' )
94+ . setHeader ( 'access-control-allow-headers' , '*' )
95+ . setHeader ( 'access-control-allow-methods' , 'GET, OPTIONS' )
7196 . status ( 200 )
7297 . send ( relayInformationDocument )
7398
0 commit comments