Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lemon-views-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"nostream": minor
---

new user-facing config field
11 changes: 11 additions & 0 deletions resources/default-settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ nip05:
domainBlacklist: []
nip45:
enabled: true
wot:
# Web of Trust filtering. When enabled, only events from pubkeys within
# the relay owner's 2-hop follow graph are accepted.
enabled: false
# The relay owner's pubkey in hex. This is the root of the trust graph.
# Required when enabled is true.
seedPubkey: ""
# A pubkey must be followed by at least this many 1-hop accounts to be trusted.
minimumFollowers: 1
# Hours between full trust graph rebuilds.
Comment thread
saniddhyaDubey marked this conversation as resolved.
refreshIntervalHours: 24
network:
maxPayloadSize: 524288
# Uncomment only when using a trusted reverse proxy and configuring trustedProxies.
Expand Down
20 changes: 20 additions & 0 deletions src/@types/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,25 @@ export interface Nip05Settings {
domainBlacklist?: string[]
}

export interface WoTSettings {
enabled: boolean
/**
* The relay owner's pubkey (hex). The trust graph is rooted here.
* Required when enabled is true.
*/
seedPubkey: Pubkey
/**
* Minimum number of 1-hop follows a pubkey must have to enter the trust filter.
* Defaults to 1.
*/
minimumFollowers: number
/**
* How many hours between full trust graph rebuilds.
* Defaults to 24.
*/
refreshIntervalHours: number
}
Comment thread
saniddhyaDubey marked this conversation as resolved.

export interface Settings {
info: Info
payments?: Payments
Expand All @@ -276,4 +295,5 @@ export interface Settings {
mirroring?: Mirroring
nip05?: Nip05Settings
nip45?: Nip45Settings
wot?: WoTSettings
}
37 changes: 37 additions & 0 deletions test/unit/utils/settings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { expect } from 'chai'
import fs from 'fs'
import { join } from 'path'
import Sinon from 'sinon'
import { mergeDeepRight } from 'ramda'
import { Settings } from '../../../src/@types/settings'

import { SettingsFileTypes, SettingsStatic } from '../../../src/utils/settings'

Expand Down Expand Up @@ -258,4 +260,39 @@ describe('SettingsStatic', () => {
)
})
})

describe('WoT settings defaults', () => {
it('default-settings.yaml contains a wot block with enabled: false', () => {
const defaults = SettingsStatic.loadAndParseYamlFile(
SettingsStatic.getDefaultSettingsFilePath()
)
expect(defaults).to.have.nested.property('wot.enabled', false)
expect(defaults).to.have.nested.property('wot.seedPubkey', '')
expect(defaults).to.have.nested.property('wot.minimumFollowers', 1)
expect(defaults).to.have.nested.property('wot.refreshIntervalHours', 24)
})

it('merging an empty user config preserves wot defaults', () => {
const defaults = SettingsStatic.loadAndParseYamlFile(
SettingsStatic.getDefaultSettingsFilePath()
)
const merged = mergeDeepRight(defaults, {}) as Settings
expect(merged.wot?.enabled).to.equal(false)
Comment thread
saniddhyaDubey marked this conversation as resolved.
Outdated
expect(merged.wot?.minimumFollowers).to.equal(1)
expect(merged.wot?.refreshIntervalHours).to.equal(24)
})

it('user config wot block overrides defaults', () => {
const defaults = SettingsStatic.loadAndParseYamlFile(
SettingsStatic.getDefaultSettingsFilePath()
)
const userConfig = { wot: { enabled: true, seedPubkey: 'abc123', minimumFollowers: 3 } }
const merged = mergeDeepRight(defaults, userConfig) as Settings
expect(merged.wot?.enabled).to.equal(true)
expect(merged.wot?.seedPubkey).to.equal('abc123')
expect(merged.wot?.minimumFollowers).to.equal(3)
// non-overridden fields stay as defaults
expect(merged.wot?.refreshIntervalHours).to.equal(24)
})
})
})
Loading