@bsv/overlay-express 2.3.0 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/mod.js +7 -1
- package/dist/cjs/mod.js.map +1 -1
- package/dist/cjs/package.json +4 -4
- package/dist/cjs/src/BanAwareDiscoveryStorage.js +78 -0
- package/dist/cjs/src/BanAwareDiscoveryStorage.js.map +1 -0
- package/dist/cjs/src/BanAwareTopicManager.js +71 -0
- package/dist/cjs/src/BanAwareTopicManager.js.map +1 -0
- package/dist/cjs/src/OverlayExpress.js +348 -95
- package/dist/cjs/src/OverlayExpress.js.map +1 -1
- package/dist/cjs/src/OverlayMonitor.js +166 -8
- package/dist/cjs/src/OverlayMonitor.js.map +1 -1
- package/dist/cjs/src/ReorgStream.js +193 -0
- package/dist/cjs/src/ReorgStream.js.map +1 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/mod.js +3 -1
- package/dist/esm/mod.js.map +1 -1
- package/dist/esm/src/BanAwareDiscoveryStorage.js +79 -0
- package/dist/esm/src/BanAwareDiscoveryStorage.js.map +1 -0
- package/dist/esm/src/BanAwareTopicManager.js +71 -0
- package/dist/esm/src/BanAwareTopicManager.js.map +1 -0
- package/dist/esm/src/OverlayExpress.js +348 -93
- package/dist/esm/src/OverlayExpress.js.map +1 -1
- package/dist/esm/src/OverlayMonitor.js +160 -6
- package/dist/esm/src/OverlayMonitor.js.map +1 -1
- package/dist/esm/src/ReorgStream.js +190 -0
- package/dist/esm/src/ReorgStream.js.map +1 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/mod.d.ts +4 -2
- package/dist/types/mod.d.ts.map +1 -1
- package/dist/types/src/BanAwareDiscoveryStorage.d.ts +36 -0
- package/dist/types/src/BanAwareDiscoveryStorage.d.ts.map +1 -0
- package/dist/types/src/BanAwareTopicManager.d.ts +28 -0
- package/dist/types/src/BanAwareTopicManager.d.ts.map +1 -0
- package/dist/types/src/OverlayExpress.d.ts +76 -4
- package/dist/types/src/OverlayExpress.d.ts.map +1 -1
- package/dist/types/src/OverlayMonitor.d.ts +45 -1
- package/dist/types/src/OverlayMonitor.d.ts.map +1 -1
- package/dist/types/src/ReorgStream.d.ts +74 -0
- package/dist/types/src/ReorgStream.d.ts.map +1 -0
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/mod.ts +7 -1
- package/package.json +4 -4
- package/src/BanAwareDiscoveryStorage.ts +91 -0
- package/src/BanAwareTopicManager.ts +87 -0
- package/src/OverlayExpress.ts +431 -100
- package/src/OverlayMonitor.ts +219 -7
- package/src/ReorgStream.ts +221 -0
- package/src/__tests__/BanAwareDiscoveryStorage.test.ts +131 -0
- package/src/__tests__/BanAwareTopicManager.test.ts +132 -0
- package/src/__tests__/OverlayMonitor.test.ts +66 -1
- package/src/__tests__/ReorgStream.test.ts +66 -0
package/mod.ts
CHANGED
|
@@ -6,14 +6,20 @@ export {
|
|
|
6
6
|
type HealthCheckResult,
|
|
7
7
|
type HealthConfig,
|
|
8
8
|
type HealthReport,
|
|
9
|
-
type HealthStatus
|
|
9
|
+
type HealthStatus,
|
|
10
|
+
type TopicAnchorHeaderResolver
|
|
10
11
|
} from './src/OverlayExpress.js'
|
|
11
12
|
export { BanService, type BannedRecord } from './src/BanService.js'
|
|
12
13
|
export { BanAwareLookupWrapper } from './src/BanAwareLookupWrapper.js'
|
|
14
|
+
export { BanAwareTopicManager } from './src/BanAwareTopicManager.js'
|
|
15
|
+
export { BanAwareSHIPStorage, BanAwareSLAPStorage } from './src/BanAwareDiscoveryStorage.js'
|
|
13
16
|
export { JanitorService, type JanitorConfig, type JanitorReport, type HostHealthResult } from './src/JanitorService.js'
|
|
14
17
|
export {
|
|
15
18
|
OverlayMonitor,
|
|
19
|
+
analyzeOverlayAnchorTip,
|
|
16
20
|
analyzeOverlayLookupResponse,
|
|
21
|
+
type OverlayAnchorProbe,
|
|
22
|
+
type OverlayAnchorProbeResult,
|
|
17
23
|
type OverlayLookupOutputSummary,
|
|
18
24
|
type OverlayLookupProbe,
|
|
19
25
|
type OverlayLookupProbeResult,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bsv/overlay-express",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "BSV Blockchain Overlay Express",
|
|
6
6
|
"main": "dist/cjs/mod.js",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@types/body-parser": "^1.19.5",
|
|
49
49
|
"@types/express": "^5.0.0",
|
|
50
50
|
"@types/jest": "^30.0.0",
|
|
51
|
-
"@types/node": "^25.9.
|
|
51
|
+
"@types/node": "^25.9.3",
|
|
52
52
|
"jest": "^30.4.2",
|
|
53
53
|
"ts-jest": "^29.4.11",
|
|
54
54
|
"ts-standard": "^12.0.2",
|
|
@@ -60,13 +60,13 @@
|
|
|
60
60
|
"@bsv/auth-express-middleware": "^2.0.6",
|
|
61
61
|
"@bsv/overlay": "^2.0.3",
|
|
62
62
|
"@bsv/overlay-discovery-services": "^2.0.3",
|
|
63
|
-
"@bsv/sdk": "^2.1.
|
|
63
|
+
"@bsv/sdk": "^2.1.4",
|
|
64
64
|
"@bsv/wallet-toolbox-client": "^2.1.28",
|
|
65
65
|
"body-parser": "^2.2.2",
|
|
66
66
|
"chalk": "^5.6.2",
|
|
67
67
|
"express": "^5.2.1",
|
|
68
68
|
"knex": "^3.2.10",
|
|
69
|
-
"mongodb": "^7.
|
|
69
|
+
"mongodb": "^7.3.0",
|
|
70
70
|
"uuid": "^14.0.0"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import * as DiscoveryServices from '@bsv/overlay-discovery-services'
|
|
2
|
+
import { BanService } from './BanService.js'
|
|
3
|
+
|
|
4
|
+
type SHIPStorage = InstanceType<typeof DiscoveryServices.SHIPStorage>
|
|
5
|
+
type SLAPStorage = InstanceType<typeof DiscoveryServices.SLAPStorage>
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Prevents banned SHIP records from being written to discovery storage.
|
|
9
|
+
*/
|
|
10
|
+
export class BanAwareSHIPStorage {
|
|
11
|
+
constructor (
|
|
12
|
+
private readonly wrapped: SHIPStorage,
|
|
13
|
+
private readonly banService: BanService,
|
|
14
|
+
private readonly logger: typeof console = console
|
|
15
|
+
) {}
|
|
16
|
+
|
|
17
|
+
async ensureIndexes (): Promise<void> {
|
|
18
|
+
return await this.wrapped.ensureIndexes()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async hasDuplicateRecord (identityKey: string, domain: string, topic: string): Promise<boolean> {
|
|
22
|
+
return await this.wrapped.hasDuplicateRecord(identityKey, domain, topic)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async storeSHIPRecord (txid: string, outputIndex: number, identityKey: string, domain: string, topic: string): Promise<void> {
|
|
26
|
+
if (await this.banService.isOutpointBanned(txid, outputIndex)) {
|
|
27
|
+
this.logger.log(`[BAN] Blocked banned outpoint ${txid}.${outputIndex} from SHIP storage`)
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
if (await this.banService.isDomainBanned(domain)) {
|
|
31
|
+
this.logger.log(`[BAN] Blocked banned domain ${domain} from SHIP storage (${txid}.${outputIndex})`)
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
return await this.wrapped.storeSHIPRecord(txid, outputIndex, identityKey, domain, topic)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async deleteSHIPRecord (txid: string, outputIndex: number): Promise<void> {
|
|
38
|
+
return await this.wrapped.deleteSHIPRecord(txid, outputIndex)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async findRecord (...args: Parameters<SHIPStorage['findRecord']>): ReturnType<SHIPStorage['findRecord']> {
|
|
42
|
+
return await this.wrapped.findRecord(...args)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async findAll (...args: Parameters<SHIPStorage['findAll']>): ReturnType<SHIPStorage['findAll']> {
|
|
46
|
+
return await this.wrapped.findAll(...args)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Prevents banned SLAP records from being written to discovery storage.
|
|
52
|
+
*/
|
|
53
|
+
export class BanAwareSLAPStorage {
|
|
54
|
+
constructor (
|
|
55
|
+
private readonly wrapped: SLAPStorage,
|
|
56
|
+
private readonly banService: BanService,
|
|
57
|
+
private readonly logger: typeof console = console
|
|
58
|
+
) {}
|
|
59
|
+
|
|
60
|
+
async ensureIndexes (): Promise<void> {
|
|
61
|
+
return await this.wrapped.ensureIndexes()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async hasDuplicateRecord (identityKey: string, domain: string, service: string): Promise<boolean> {
|
|
65
|
+
return await this.wrapped.hasDuplicateRecord(identityKey, domain, service)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async storeSLAPRecord (txid: string, outputIndex: number, identityKey: string, domain: string, service: string): Promise<void> {
|
|
69
|
+
if (await this.banService.isOutpointBanned(txid, outputIndex)) {
|
|
70
|
+
this.logger.log(`[BAN] Blocked banned outpoint ${txid}.${outputIndex} from SLAP storage`)
|
|
71
|
+
return
|
|
72
|
+
}
|
|
73
|
+
if (await this.banService.isDomainBanned(domain)) {
|
|
74
|
+
this.logger.log(`[BAN] Blocked banned domain ${domain} from SLAP storage (${txid}.${outputIndex})`)
|
|
75
|
+
return
|
|
76
|
+
}
|
|
77
|
+
return await this.wrapped.storeSLAPRecord(txid, outputIndex, identityKey, domain, service)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async deleteSLAPRecord (txid: string, outputIndex: number): Promise<void> {
|
|
81
|
+
return await this.wrapped.deleteSLAPRecord(txid, outputIndex)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async findRecord (...args: Parameters<SLAPStorage['findRecord']>): ReturnType<SLAPStorage['findRecord']> {
|
|
85
|
+
return await this.wrapped.findRecord(...args)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async findAll (...args: Parameters<SLAPStorage['findAll']>): ReturnType<SLAPStorage['findAll']> {
|
|
89
|
+
return await this.wrapped.findAll(...args)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { TopicManager } from '@bsv/overlay'
|
|
2
|
+
import { AdmittanceInstructions, PushDrop, Transaction, Utils } from '@bsv/sdk'
|
|
3
|
+
import { BanService } from './BanService.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Filters banned SHIP or SLAP advertisement outputs before the overlay engine
|
|
7
|
+
* admits them into topic storage.
|
|
8
|
+
*/
|
|
9
|
+
export class BanAwareTopicManager implements TopicManager {
|
|
10
|
+
constructor (
|
|
11
|
+
private readonly wrapped: TopicManager,
|
|
12
|
+
private readonly banService: BanService,
|
|
13
|
+
private readonly protocol: 'SHIP' | 'SLAP',
|
|
14
|
+
private readonly logger: typeof console = console
|
|
15
|
+
) {}
|
|
16
|
+
|
|
17
|
+
async identifyAdmissibleOutputs (
|
|
18
|
+
beef: number[],
|
|
19
|
+
previousCoins: number[],
|
|
20
|
+
offChainValues?: number[],
|
|
21
|
+
mode?: 'historical-tx' | 'current-tx' | 'historical-tx-no-spv'
|
|
22
|
+
): Promise<AdmittanceInstructions> {
|
|
23
|
+
const instructions = await this.wrapped.identifyAdmissibleOutputs(beef, previousCoins, offChainValues, mode)
|
|
24
|
+
if (instructions.outputsToAdmit.length === 0) return instructions
|
|
25
|
+
|
|
26
|
+
let tx: Transaction
|
|
27
|
+
try {
|
|
28
|
+
tx = Transaction.fromBEEF(beef)
|
|
29
|
+
} catch {
|
|
30
|
+
return instructions
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const txid = tx.id('hex')
|
|
34
|
+
const outputsToAdmit: number[] = []
|
|
35
|
+
|
|
36
|
+
for (const outputIndex of instructions.outputsToAdmit) {
|
|
37
|
+
if (await this.banService.isOutpointBanned(txid, outputIndex)) {
|
|
38
|
+
this.logger.log(`[BAN] Blocked banned outpoint ${txid}.${outputIndex} from ${this.protocol} topic admittance`)
|
|
39
|
+
continue
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const output = tx.outputs[outputIndex]
|
|
43
|
+
if (output === undefined) continue
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
const result = PushDrop.decode(output.lockingScript)
|
|
47
|
+
if (result.fields.length >= 3 && Utils.toUTF8(result.fields[0]) === this.protocol) {
|
|
48
|
+
const domain = Utils.toUTF8(result.fields[2])
|
|
49
|
+
if (await this.banService.isDomainBanned(domain)) {
|
|
50
|
+
this.logger.log(`[BAN] Blocked banned domain ${domain} from ${this.protocol} topic admittance (${txid}.${outputIndex})`)
|
|
51
|
+
continue
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
} catch {
|
|
55
|
+
// Non PushDrop outputs remain subject to the wrapped manager's decision.
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
outputsToAdmit.push(outputIndex)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
...instructions,
|
|
63
|
+
outputsToAdmit
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async identifyNeededInputs (beef: number[], offChainValues?: number[]): Promise<Array<{ txid: string, outputIndex: number }>> {
|
|
68
|
+
if (typeof this.wrapped.identifyNeededInputs === 'function') {
|
|
69
|
+
return await this.wrapped.identifyNeededInputs(beef, offChainValues)
|
|
70
|
+
}
|
|
71
|
+
return []
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async getDocumentation (): Promise<string> {
|
|
75
|
+
return await this.wrapped.getDocumentation()
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async getMetaData (): Promise<{
|
|
79
|
+
name: string
|
|
80
|
+
shortDescription: string
|
|
81
|
+
iconURL?: string
|
|
82
|
+
version?: string
|
|
83
|
+
informationURL?: string
|
|
84
|
+
}> {
|
|
85
|
+
return await this.wrapped.getMetaData()
|
|
86
|
+
}
|
|
87
|
+
}
|