Skip to content

Commit d4e91ce

Browse files
feat: config schema for wot
1 parent 80e2542 commit d4e91ce

3 files changed

Lines changed: 68 additions & 0 deletions

File tree

resources/default-settings.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ nip05:
6262
domainBlacklist: []
6363
nip45:
6464
enabled: true
65+
wot:
66+
# Web of Trust filtering. When enabled, only events from pubkeys within
67+
# the relay owner's 2-hop follow graph are accepted.
68+
enabled: false
69+
# The relay owner's pubkey in hex. This is the root of the trust graph.
70+
# Required when enabled is true.
71+
seedPubkey: ""
72+
# A pubkey must be followed by at least this many 1-hop accounts to be trusted.
73+
minimumFollowers: 1
74+
# Hours between full trust graph rebuilds.
75+
refreshIntervalHours: 24
6576
network:
6677
maxPayloadSize: 524288
6778
# Uncomment only when using a trusted reverse proxy and configuring trustedProxies.

src/@types/settings.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,25 @@ export interface Nip05Settings {
266266
domainBlacklist?: string[]
267267
}
268268

269+
export interface WoTSettings {
270+
enabled: boolean
271+
/**
272+
* The relay owner's pubkey (hex). The trust graph is rooted here.
273+
* Required when enabled is true.
274+
*/
275+
seedPubkey: Pubkey
276+
/**
277+
* Minimum number of 1-hop follows a pubkey must have to enter the trust filter.
278+
* Defaults to 1.
279+
*/
280+
minimumFollowers: number
281+
/**
282+
* How many hours between full trust graph rebuilds.
283+
* Defaults to 24.
284+
*/
285+
refreshIntervalHours: number
286+
}
287+
269288
export interface Settings {
270289
info: Info
271290
payments?: Payments
@@ -276,4 +295,5 @@ export interface Settings {
276295
mirroring?: Mirroring
277296
nip05?: Nip05Settings
278297
nip45?: Nip45Settings
298+
wot?: WoTSettings
279299
}

test/unit/utils/settings.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { expect } from 'chai'
22
import fs from 'fs'
33
import { join } from 'path'
44
import Sinon from 'sinon'
5+
import { mergeDeepRight } from 'ramda'
6+
import { Settings } from '../../../src/@types/settings'
57

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

@@ -258,4 +260,39 @@ describe('SettingsStatic', () => {
258260
)
259261
})
260262
})
263+
264+
describe('WoT settings defaults', () => {
265+
it('default-settings.yaml contains a wot block with enabled: false', () => {
266+
const defaults = SettingsStatic.loadAndParseYamlFile(
267+
SettingsStatic.getDefaultSettingsFilePath()
268+
)
269+
expect(defaults).to.have.nested.property('wot.enabled', false)
270+
expect(defaults).to.have.nested.property('wot.seedPubkey', '')
271+
expect(defaults).to.have.nested.property('wot.minimumFollowers', 1)
272+
expect(defaults).to.have.nested.property('wot.refreshIntervalHours', 24)
273+
})
274+
275+
it('merging an empty user config preserves wot defaults', () => {
276+
const defaults = SettingsStatic.loadAndParseYamlFile(
277+
SettingsStatic.getDefaultSettingsFilePath()
278+
)
279+
const merged = mergeDeepRight(defaults, {}) as Settings
280+
expect(merged.wot?.enabled).to.equal(false)
281+
expect(merged.wot?.minimumFollowers).to.equal(1)
282+
expect(merged.wot?.refreshIntervalHours).to.equal(24)
283+
})
284+
285+
it('user config wot block overrides defaults', () => {
286+
const defaults = SettingsStatic.loadAndParseYamlFile(
287+
SettingsStatic.getDefaultSettingsFilePath()
288+
)
289+
const userConfig = { wot: { enabled: true, seedPubkey: 'abc123', minimumFollowers: 3 } }
290+
const merged = mergeDeepRight(defaults, userConfig) as Settings
291+
expect(merged.wot?.enabled).to.equal(true)
292+
expect(merged.wot?.seedPubkey).to.equal('abc123')
293+
expect(merged.wot?.minimumFollowers).to.equal(3)
294+
// non-overridden fields stay as defaults
295+
expect(merged.wot?.refreshIntervalHours).to.equal(24)
296+
})
297+
})
261298
})

0 commit comments

Comments
 (0)