Skip to content

Commit 59c42a4

Browse files
authored
Merge pull request #376 from bsv-blockchain/overlay-reputation
Overlay reputation
2 parents 8f5ce1d + b2f5d22 commit 59c42a4

File tree

8 files changed

+530
-8
lines changed

8 files changed

+530
-8
lines changed

CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# CHANGELOG for `@bsv/sdk`
22

3-
All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
3+
All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec2.0.0.html).
44

55
## Table of Contents
66

77
- [Unreleased](#unreleased)
8+
- [1.8.13 - 2025-11-06](#1813---2025-11-06)
9+
- [1.8.12 - 2025-11-06](#1812---2025-11-06)
810
- [1.8.11 - 2025-10-30](#1811---2025-10-30)
911
- [1.8.10 - 2025-10-28](#1810---2025-10-28)
1012
- [1.8.9 - 2025-10-27](#189---2025-10-27)
@@ -171,6 +173,14 @@ All notable changes to this project will be documented in this file. The format
171173

172174
---
173175

176+
### [1.8.13] - 2025-11-06
177+
178+
### Added
179+
180+
- LookupResolver: Support for custom overlay ranking to allow for expedited lookups and reputation tracking.
181+
182+
---
183+
174184
### [1.8.12] - 2025-11-06
175185

176186
### Fixed

docs/reference/overlay-tools.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
1111
| [LookupResolverConfig](#interface-lookupresolverconfig) |
1212
| [OverlayBroadcastFacilitator](#interface-overlaybroadcastfacilitator) |
1313
| [OverlayLookupFacilitator](#interface-overlaylookupfacilitator) |
14+
| [RankedHost](#interface-rankedhost) |
1415
| [SHIPBroadcasterConfig](#interface-shipbroadcasterconfig) |
1516
| [TaggedBEEF](#interface-taggedbeef) |
1617

@@ -101,6 +102,10 @@ export interface LookupResolverConfig {
101102
hostOverrides?: Record<string, string[]>;
102103
additionalHosts?: Record<string, string[]>;
103104
cache?: CacheOptions;
105+
reputationStorage?: "localStorage" | {
106+
get: (key: string) => string | null | undefined;
107+
set: (key: string, value: string) => void;
108+
};
104109
}
105110
```
106111

@@ -150,6 +155,17 @@ The network preset to use, unless other options override it.
150155
networkPreset?: "mainnet" | "testnet" | "local"
151156
```
152157

158+
#### Property reputationStorage
159+
160+
Optional storage for host reputation data.
161+
162+
```ts
163+
reputationStorage?: "localStorage" | {
164+
get: (key: string) => string | null | undefined;
165+
set: (key: string, value: string) => void;
166+
}
167+
```
168+
153169
#### Property slapTrackers
154170

155171
The list of SLAP trackers queried to resolve Overlay Services hosts for a given lookup service.
@@ -199,6 +215,17 @@ See also: [LookupAnswer](./overlay-tools.md#type-lookupanswer), [LookupQuestion]
199215

200216
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
201217

218+
---
219+
### Interface: RankedHost
220+
221+
```ts
222+
export interface RankedHost extends HostReputationEntry {
223+
score: number;
224+
}
225+
```
226+
227+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
228+
202229
---
203230
### Interface: SHIPBroadcasterConfig
204231

@@ -294,6 +321,7 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
294321
| --- |
295322
| [HTTPSOverlayBroadcastFacilitator](#class-httpsoverlaybroadcastfacilitator) |
296323
| [HTTPSOverlayLookupFacilitator](#class-httpsoverlaylookupfacilitator) |
324+
| [HostReputationTracker](#class-hostreputationtracker) |
297325
| [LookupResolver](#class-lookupresolver) |
298326
| [OverlayAdminTokenTemplate](#class-overlayadmintokentemplate) |
299327
| [TopicBroadcaster](#class-topicbroadcaster) |
@@ -333,6 +361,24 @@ See also: [LookupAnswer](./overlay-tools.md#type-lookupanswer), [LookupQuestion]
333361

334362
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
335363

364+
---
365+
### Class: HostReputationTracker
366+
367+
```ts
368+
export class HostReputationTracker {
369+
constructor(store?: KeyValueStore)
370+
reset(): void
371+
recordSuccess(host: string, latencyMs: number): void
372+
recordFailure(host: string, reason?: unknown): void
373+
rankHosts(hosts: string[], now: number = Date.now()): RankedHost[]
374+
snapshot(host: string): HostReputationEntry | undefined
375+
}
376+
```
377+
378+
See also: [RankedHost](./overlay-tools.md#interface-rankedhost)
379+
380+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
381+
336382
---
337383
### Class: LookupResolver
338384

@@ -569,6 +615,7 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
569615
| --- |
570616
| [DEFAULT_SLAP_TRACKERS](#variable-default_slap_trackers) |
571617
| [DEFAULT_TESTNET_SLAP_TRACKERS](#variable-default_testnet_slap_trackers) |
618+
| [getOverlayHostReputationTracker](#variable-getoverlayhostreputationtracker) |
572619
573620
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
574621
@@ -599,3 +646,14 @@ DEFAULT_TESTNET_SLAP_TRACKERS: string[] = [
599646
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
600647
601648
---
649+
### Variable: getOverlayHostReputationTracker
650+
651+
```ts
652+
getOverlayHostReputationTracker = (): HostReputationTracker => globalTracker
653+
```
654+
655+
See also: [HostReputationTracker](./overlay-tools.md#class-hostreputationtracker)
656+
657+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
658+
659+
---

docs/reference/primitives.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4764,6 +4764,7 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
47644764
| [red](#function-red) |
47654765
| [toArray](#function-toarray) |
47664766
| [toBase64](#function-tobase64) |
4767+
| [verifyNotNull](#function-verifynotnull) |
47674768
47684769
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
47694770
@@ -4889,6 +4890,38 @@ Argument Details
48894890

48904891
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
48914892

4893+
---
4894+
### Function: verifyNotNull
4895+
4896+
Verifies that a value is not null or undefined, throwing an error if it is.
4897+
4898+
Example
4899+
4900+
```ts
4901+
const myValue = verifyNotNull(someValue, 'someValue must be defined')
4902+
```
4903+
4904+
```ts
4905+
export function verifyNotNull<T>(value: T | undefined | null, errorMessage: string = "Expected a valid value, but got undefined or null."): T
4906+
```
4907+
4908+
Returns
4909+
4910+
- The verified value
4911+
4912+
Argument Details
4913+
4914+
+ **value**
4915+
+ The value to verify
4916+
+ **errorMessage**
4917+
+ The error message to throw if the value is null or undefined
4918+
4919+
Throws
4920+
4921+
- If the value is null or undefined
4922+
4923+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
4924+
48924925
---
48934926
## Types
48944927

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@bsv/sdk",
3-
"version": "1.8.12",
3+
"version": "1.8.13",
44
"type": "module",
55
"description": "BSV Blockchain Software Development Kit",
66
"main": "dist/cjs/mod.js",

0 commit comments

Comments
 (0)