@bsv/overlay-discovery-services 1.4.0 → 1.4.2
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/package.json +4 -4
- package/dist/cjs/src/LegacyNinjaAdvertiser.js +235 -0
- package/dist/cjs/src/LegacyNinjaAdvertiser.js.map +1 -0
- package/dist/cjs/src/SHIP/SHIPLookupService.js +43 -11
- package/dist/cjs/src/SHIP/SHIPLookupService.js.map +1 -1
- package/dist/cjs/src/SHIP/SHIPStorage.js +33 -10
- package/dist/cjs/src/SHIP/SHIPStorage.js.map +1 -1
- package/dist/cjs/src/SHIP/SHIPTopicManager.js.map +1 -1
- package/dist/cjs/src/SLAP/SLAPLookupService.js +57 -22
- package/dist/cjs/src/SLAP/SLAPLookupService.js.map +1 -1
- package/dist/cjs/src/SLAP/SLAPStorage.js +29 -6
- package/dist/cjs/src/SLAP/SLAPStorage.js.map +1 -1
- package/dist/cjs/src/utils/generateDocs.js +81 -0
- package/dist/cjs/src/utils/generateDocs.js.map +1 -0
- package/dist/cjs/src/utils/getDocumentation.js +22 -0
- package/dist/cjs/src/utils/getDocumentation.js.map +1 -0
- package/dist/cjs/src/utils/isAdvertisableURI.js +21 -21
- package/dist/cjs/src/utils/isAdvertisableURI.js.map +1 -1
- package/dist/cjs/src/utils/isValidDomain.js +15 -0
- package/dist/cjs/src/utils/isValidDomain.js.map +1 -0
- package/dist/cjs/src/utils/isValidServiceName.js +14 -0
- package/dist/cjs/src/utils/isValidServiceName.js.map +1 -0
- package/dist/cjs/src/utils/verifyToken.js +22 -0
- package/dist/cjs/src/utils/verifyToken.js.map +1 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/LegacyNinjaAdvertiser.js +233 -0
- package/dist/esm/src/LegacyNinjaAdvertiser.js.map +1 -0
- package/dist/esm/src/SHIP/SHIPLookupService.js +43 -11
- package/dist/esm/src/SHIP/SHIPLookupService.js.map +1 -1
- package/dist/esm/src/SHIP/SHIPStorage.js +32 -10
- package/dist/esm/src/SHIP/SHIPStorage.js.map +1 -1
- package/dist/esm/src/SHIP/SHIPTopicManager.js.map +1 -1
- package/dist/esm/src/SLAP/SLAPLookupService.js +57 -22
- package/dist/esm/src/SLAP/SLAPLookupService.js.map +1 -1
- package/dist/esm/src/SLAP/SLAPStorage.js +28 -6
- package/dist/esm/src/SLAP/SLAPStorage.js.map +1 -1
- package/dist/esm/src/utils/generateDocs.js +46 -0
- package/dist/esm/src/utils/generateDocs.js.map +1 -0
- package/dist/esm/src/utils/getDocumentation.js +20 -0
- package/dist/esm/src/utils/getDocumentation.js.map +1 -0
- package/dist/esm/src/utils/isAdvertisableURI.js +21 -21
- package/dist/esm/src/utils/isAdvertisableURI.js.map +1 -1
- package/dist/esm/src/utils/isValidDomain.js +11 -0
- package/dist/esm/src/utils/isValidDomain.js.map +1 -0
- package/dist/esm/src/utils/isValidServiceName.js +10 -0
- package/dist/esm/src/utils/isValidServiceName.js.map +1 -0
- package/dist/esm/src/utils/verifyToken.js +18 -0
- package/dist/esm/src/utils/verifyToken.js.map +1 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/LegacyNinjaAdvertiser.d.ts +60 -0
- package/dist/types/src/LegacyNinjaAdvertiser.d.ts.map +1 -0
- package/dist/types/src/SHIP/SHIPLookupService.d.ts.map +1 -1
- package/dist/types/src/SHIP/SHIPStorage.d.ts +8 -5
- package/dist/types/src/SHIP/SHIPStorage.d.ts.map +1 -1
- package/dist/types/src/SHIP/SHIPTopicManager.d.ts.map +1 -1
- package/dist/types/src/SLAP/SLAPLookupService.d.ts.map +1 -1
- package/dist/types/src/SLAP/SLAPStorage.d.ts +4 -1
- package/dist/types/src/SLAP/SLAPStorage.d.ts.map +1 -1
- package/dist/types/src/SLAP/SLAPTopicManager.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +8 -0
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/src/utils/generateDocs.d.ts +2 -0
- package/dist/types/src/utils/generateDocs.d.ts.map +1 -0
- package/dist/types/src/utils/getDocumentation.d.ts +8 -0
- package/dist/types/src/utils/getDocumentation.d.ts.map +1 -0
- package/dist/types/src/utils/isAdvertisableURI.d.ts.map +1 -1
- package/dist/types/src/utils/isValidDomain.d.ts +7 -0
- package/dist/types/src/utils/isValidDomain.d.ts.map +1 -0
- package/dist/types/src/utils/isValidServiceName.d.ts +7 -0
- package/dist/types/src/utils/isValidServiceName.d.ts.map +1 -0
- package/dist/types/src/utils/verifyToken.d.ts +12 -0
- package/dist/types/src/utils/verifyToken.d.ts.map +1 -0
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/SHIP/SHIPLookupService.ts +57 -17
- package/src/SHIP/SHIPStorage.ts +45 -15
- package/src/SHIP/SHIPTopicManager.ts +3 -3
- package/src/SLAP/SLAPLookup.docs.ts +1 -1
- package/src/SLAP/SLAPLookupService.ts +64 -26
- package/src/SLAP/SLAPStorage.ts +41 -11
- package/src/SLAP/SLAPTopicManager.ts +3 -3
- package/src/types.ts +8 -0
- package/src/utils/isAdvertisableURI.ts +50 -50
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Checks if the provided URI is advertisable, with a recognized URI prefix.
|
|
3
3
|
* Applies scheme-specific validation rules as defined by the BRC-101 overlay advertisement spec.
|
|
4
|
-
*
|
|
4
|
+
*
|
|
5
5
|
* - For HTTPS-based schemes (https://, https+bsvauth+smf://, https+bsvauth+scrypt-offchain://, https+rtt://)
|
|
6
6
|
* - Uses the URL parser (after substituting the custom scheme with "https:" where needed)
|
|
7
7
|
* - Disallows "localhost" as hostname
|
|
@@ -16,86 +16,86 @@
|
|
|
16
16
|
* @returns True if the URI is valid and advertisable, false otherwise.
|
|
17
17
|
*/
|
|
18
18
|
export const isAdvertisableURI = (uri: string): boolean => {
|
|
19
|
-
if (typeof uri !== 'string' || uri.trim() === '') return false
|
|
19
|
+
if (typeof uri !== 'string' || uri.trim() === '') return false
|
|
20
20
|
|
|
21
21
|
// Helper function: validate a URL by substituting its scheme if needed.
|
|
22
22
|
const validateCustomHttpsURI = (uri: string, prefix: string): boolean => {
|
|
23
23
|
try {
|
|
24
|
-
const modifiedURI = uri.replace(prefix,
|
|
25
|
-
const parsed = new URL(modifiedURI)
|
|
26
|
-
if (parsed.hostname.toLowerCase() ===
|
|
27
|
-
if (parsed.pathname !== '/') return false
|
|
28
|
-
return true
|
|
24
|
+
const modifiedURI = uri.replace(prefix, 'https://')
|
|
25
|
+
const parsed = new URL(modifiedURI)
|
|
26
|
+
if (parsed.hostname.toLowerCase() === 'localhost') return false
|
|
27
|
+
if (parsed.pathname !== '/') return false
|
|
28
|
+
return true
|
|
29
29
|
} catch (e) {
|
|
30
|
-
return false
|
|
30
|
+
return false
|
|
31
31
|
}
|
|
32
|
-
}
|
|
32
|
+
}
|
|
33
33
|
|
|
34
34
|
// HTTPS-based schemes – disallow localhost.
|
|
35
|
-
if (uri.startsWith(
|
|
36
|
-
return validateCustomHttpsURI(uri,
|
|
35
|
+
if (uri.startsWith('https://')) {
|
|
36
|
+
return validateCustomHttpsURI(uri, 'https://')
|
|
37
37
|
}
|
|
38
38
|
// Plain auth over HTTPS, but no payment can be collected
|
|
39
|
-
else if (uri.startsWith(
|
|
40
|
-
return validateCustomHttpsURI(uri,
|
|
39
|
+
else if (uri.startsWith('https+bsvauth://')) {
|
|
40
|
+
return validateCustomHttpsURI(uri, 'https+bsvauth://')
|
|
41
41
|
}
|
|
42
42
|
// Auth and payment over HTTPS
|
|
43
|
-
else if (uri.startsWith(
|
|
44
|
-
return validateCustomHttpsURI(uri,
|
|
43
|
+
else if (uri.startsWith('https+bsvauth+smf://')) {
|
|
44
|
+
return validateCustomHttpsURI(uri, 'https+bsvauth+smf://')
|
|
45
45
|
}
|
|
46
46
|
// A protocol allowing you to also supply sCrypt off-chain values to the topical admissibility checking context
|
|
47
|
-
else if (uri.startsWith(
|
|
48
|
-
return validateCustomHttpsURI(uri,
|
|
47
|
+
else if (uri.startsWith('https+bsvauth+scrypt-offchain://')) {
|
|
48
|
+
return validateCustomHttpsURI(uri, 'https+bsvauth+scrypt-offchain://')
|
|
49
49
|
}
|
|
50
50
|
// A protocol allowing overlays that deal with real-time transactions (non-finals)
|
|
51
|
-
else if (uri.startsWith(
|
|
52
|
-
return validateCustomHttpsURI(uri,
|
|
51
|
+
else if (uri.startsWith('https+rtt://')) {
|
|
52
|
+
return validateCustomHttpsURI(uri, 'https+rtt://')
|
|
53
53
|
}
|
|
54
54
|
// WSS for real-time event-listening lookups.
|
|
55
|
-
else if (uri.startsWith(
|
|
55
|
+
else if (uri.startsWith('wss://')) {
|
|
56
56
|
try {
|
|
57
|
-
const parsed = new URL(uri)
|
|
58
|
-
if (parsed.protocol !==
|
|
59
|
-
if (parsed.hostname.toLowerCase() ===
|
|
60
|
-
return true
|
|
57
|
+
const parsed = new URL(uri)
|
|
58
|
+
if (parsed.protocol !== 'wss:') return false
|
|
59
|
+
if (parsed.hostname.toLowerCase() === 'localhost') return false
|
|
60
|
+
return true
|
|
61
61
|
} catch (e) {
|
|
62
|
-
return false
|
|
62
|
+
return false
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
// JS8 Call–based advertisement.
|
|
66
|
-
else if (uri.startsWith(
|
|
66
|
+
else if (uri.startsWith('js8c+bsvauth+smf:')) {
|
|
67
67
|
// Expect a query string with parameters.
|
|
68
|
-
const queryIndex = uri.indexOf(
|
|
69
|
-
if (queryIndex === -1) return false
|
|
68
|
+
const queryIndex = uri.indexOf('?')
|
|
69
|
+
if (queryIndex === -1) return false
|
|
70
70
|
|
|
71
|
-
const queryStr = uri.substring(queryIndex)
|
|
72
|
-
const params = new URLSearchParams(queryStr)
|
|
71
|
+
const queryStr = uri.substring(queryIndex)
|
|
72
|
+
const params = new URLSearchParams(queryStr)
|
|
73
73
|
|
|
74
74
|
// Required parameters: lat, long, freq, and radius.
|
|
75
|
-
const latStr = params.get(
|
|
76
|
-
const longStr = params.get(
|
|
77
|
-
const freqStr = params.get(
|
|
78
|
-
const radiusStr = params.get(
|
|
75
|
+
const latStr = params.get('lat')
|
|
76
|
+
const longStr = params.get('long')
|
|
77
|
+
const freqStr = params.get('freq')
|
|
78
|
+
const radiusStr = params.get('radius')
|
|
79
79
|
|
|
80
|
-
if (!latStr || !longStr || !freqStr || !radiusStr) return false
|
|
80
|
+
if (!latStr || !longStr || !freqStr || !radiusStr) return false
|
|
81
81
|
|
|
82
82
|
// Validate latitude and longitude ranges.
|
|
83
|
-
const lat = parseFloat(latStr)
|
|
84
|
-
const lon = parseFloat(longStr)
|
|
85
|
-
if (isNaN(lat) || lat < -90 || lat > 90) return false
|
|
86
|
-
if (isNaN(lon) || lon < -180 || lon > 180) return false
|
|
83
|
+
const lat = parseFloat(latStr)
|
|
84
|
+
const lon = parseFloat(longStr)
|
|
85
|
+
if (isNaN(lat) || lat < -90 || lat > 90) return false
|
|
86
|
+
if (isNaN(lon) || lon < -180 || lon > 180) return false
|
|
87
87
|
|
|
88
88
|
// Validate frequency: extract the first number from the freq string.
|
|
89
|
-
const freqMatch = freqStr.match(/(\d+(\.\d+)?)/)
|
|
90
|
-
if (!freqMatch) return false
|
|
91
|
-
const freqVal = parseFloat(freqMatch[1])
|
|
92
|
-
if (isNaN(freqVal) || freqVal <= 0) return false
|
|
89
|
+
const freqMatch = freqStr.match(/(\d+(\.\d+)?)/)
|
|
90
|
+
if (!freqMatch) return false
|
|
91
|
+
const freqVal = parseFloat(freqMatch[1])
|
|
92
|
+
if (isNaN(freqVal) || freqVal <= 0) return false
|
|
93
93
|
|
|
94
94
|
// Validate radius: extract the first number from the radius string.
|
|
95
|
-
const radiusMatch = radiusStr.match(/(\d+(\.\d+)?)/)
|
|
96
|
-
if (!radiusMatch) return false
|
|
97
|
-
const radiusVal = parseFloat(radiusMatch[1])
|
|
98
|
-
if (isNaN(radiusVal) || radiusVal <= 0) return false
|
|
95
|
+
const radiusMatch = radiusStr.match(/(\d+(\.\d+)?)/)
|
|
96
|
+
if (!radiusMatch) return false
|
|
97
|
+
const radiusVal = parseFloat(radiusMatch[1])
|
|
98
|
+
if (isNaN(radiusVal) || radiusVal <= 0) return false
|
|
99
99
|
|
|
100
100
|
// JS8 is more of a "demo" / "example". We include it to demonstrate that
|
|
101
101
|
// overlays can be advertised in many, many ways.
|
|
@@ -103,12 +103,12 @@ export const isAdvertisableURI = (uri: string): boolean => {
|
|
|
103
103
|
// restrict the radius to a maximum value, establish and check for allowed units.
|
|
104
104
|
// Doing overlays over HF radio with js8c would be very interesting none the less.
|
|
105
105
|
// For now, we assume any positive numbers are acceptable.
|
|
106
|
-
return true
|
|
106
|
+
return true
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
// Add more overlay advertisement protocols here!
|
|
110
110
|
// Make JS8Call actually work! Go read BRC-101!
|
|
111
111
|
|
|
112
112
|
// If none of the known prefixes match, the URI is not advertisable.
|
|
113
|
-
return false
|
|
114
|
-
}
|
|
113
|
+
return false
|
|
114
|
+
}
|