@bsv/overlay-discovery-services 1.2.0 → 1.3.0
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 +2 -2
- package/dist/cjs/src/SHIP/SHIPLookupService.js +12 -38
- package/dist/cjs/src/SHIP/SHIPLookupService.js.map +1 -1
- package/dist/cjs/src/SLAP/SLAPLookupService.js +12 -38
- package/dist/cjs/src/SLAP/SLAPLookupService.js.map +1 -1
- package/dist/cjs/src/WalletAdvertiser.js +13 -6
- package/dist/cjs/src/WalletAdvertiser.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/SHIP/SHIPLookupService.js +12 -38
- package/dist/esm/src/SHIP/SHIPLookupService.js.map +1 -1
- package/dist/esm/src/SLAP/SLAPLookupService.js +12 -38
- package/dist/esm/src/SLAP/SLAPLookupService.js.map +1 -1
- package/dist/esm/src/WalletAdvertiser.js +13 -6
- package/dist/esm/src/WalletAdvertiser.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/SHIP/SHIPLookupService.d.ts +6 -37
- package/dist/types/src/SHIP/SHIPLookupService.d.ts.map +1 -1
- package/dist/types/src/SLAP/SLAPLookupService.d.ts +6 -37
- package/dist/types/src/SLAP/SLAPLookupService.d.ts.map +1 -1
- package/dist/types/src/WalletAdvertiser.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/SHIP/SHIPLookupService.ts +12 -39
- package/src/SLAP/SLAPLookupService.ts +12 -39
- package/src/WalletAdvertiser.ts +12 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bsv/overlay-discovery-services",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "BSV Blockchain Overlay Services Engine",
|
|
6
6
|
"main": "dist/cjs/mod.js",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"typescript": "^5.2.2"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@bsv/overlay": "^0.1
|
|
65
|
+
"@bsv/overlay": "^0.2.1",
|
|
66
66
|
"@bsv/sdk": "^1.4.6",
|
|
67
67
|
"@bsv/wallet-toolbox-client": "^1.2.10",
|
|
68
68
|
"mongodb": "^6.11.0"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { LookupService, LookupQuestion, LookupAnswer, LookupFormula } from '@bsv/overlay'
|
|
1
|
+
import { LookupService, LookupQuestion, LookupAnswer, LookupFormula, AdmissionMode, OutputAdmittedByTopic, OutputSpent, SpendNotificationMode } from '@bsv/overlay'
|
|
2
2
|
import { SHIPStorage } from './SHIPStorage.js'
|
|
3
|
-
import {
|
|
3
|
+
import { PushDrop, Utils } from '@bsv/sdk'
|
|
4
4
|
import { SHIPQuery } from 'src/types.js'
|
|
5
5
|
import SHIPLookupDocs from './SHIPLookup.docs.js'
|
|
6
6
|
|
|
@@ -11,18 +11,15 @@ import SHIPLookupDocs from './SHIPLookup.docs.js'
|
|
|
11
11
|
* within the overlay network.
|
|
12
12
|
*/
|
|
13
13
|
export class SHIPLookupService implements LookupService {
|
|
14
|
+
admissionMode: AdmissionMode = 'locking-script'
|
|
15
|
+
spendNotificationMode: SpendNotificationMode = 'none'
|
|
14
16
|
constructor(public storage: SHIPStorage) { }
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* @param outputIndex - The index of the output in the transaction.
|
|
20
|
-
* @param outputScript - The script of the output to be processed.
|
|
21
|
-
* @param topic - The topic associated with the output.
|
|
22
|
-
*/
|
|
23
|
-
async outputAdded?(txid: string, outputIndex: number, outputScript: Script, topic: string): Promise<void> {
|
|
18
|
+
async outputAdmittedByTopic(payload: OutputAdmittedByTopic): Promise<void> {
|
|
19
|
+
if (payload.mode !== 'locking-script') throw new Error('Invalid payload')
|
|
20
|
+
const { topic, lockingScript, txid, outputIndex } = payload
|
|
24
21
|
if (topic !== 'tm_ship') return
|
|
25
|
-
const result = PushDrop.decode(
|
|
22
|
+
const result = PushDrop.decode(lockingScript)
|
|
26
23
|
const shipIdentifier = Utils.toUTF8(result.fields[0])
|
|
27
24
|
const identityKey = Utils.toHex(result.fields[1])
|
|
28
25
|
const domain = Utils.toUTF8(result.fields[2])
|
|
@@ -31,33 +28,17 @@ export class SHIPLookupService implements LookupService {
|
|
|
31
28
|
await this.storage.storeSHIPRecord(txid, outputIndex, identityKey, domain, topicSupported)
|
|
32
29
|
}
|
|
33
30
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
* @param outputIndex - The index of the spent output.
|
|
38
|
-
* @param topic - The topic associated with the spent output.
|
|
39
|
-
*/
|
|
40
|
-
async outputSpent?(txid: string, outputIndex: number, topic: string): Promise<void> {
|
|
31
|
+
async outputSpent(payload: OutputSpent): Promise<void> {
|
|
32
|
+
if (payload.mode !== 'none') throw new Error('Invalid payload')
|
|
33
|
+
const { topic, txid, outputIndex } = payload
|
|
41
34
|
if (topic !== 'tm_ship') return
|
|
42
35
|
await this.storage.deleteSHIPRecord(txid, outputIndex)
|
|
43
36
|
}
|
|
44
37
|
|
|
45
|
-
|
|
46
|
-
* Handles the deletion of an output in the topic.
|
|
47
|
-
* @param txid - The transaction ID of the deleted output.
|
|
48
|
-
* @param outputIndex - The index of the deleted output.
|
|
49
|
-
* @param topic - The topic associated with the deleted output.
|
|
50
|
-
*/
|
|
51
|
-
async outputDeleted?(txid: string, outputIndex: number, topic: string): Promise<void> {
|
|
52
|
-
if (topic !== 'tm_ship') return
|
|
38
|
+
async outputEvicted (txid: string, outputIndex: number): Promise<void> {
|
|
53
39
|
await this.storage.deleteSHIPRecord(txid, outputIndex)
|
|
54
40
|
}
|
|
55
41
|
|
|
56
|
-
/**
|
|
57
|
-
* Answers a lookup query.
|
|
58
|
-
* @param question - The lookup question to be answered.
|
|
59
|
-
* @returns A promise that resolves to a lookup answer or formula.
|
|
60
|
-
*/
|
|
61
42
|
async lookup(question: LookupQuestion): Promise<LookupAnswer | LookupFormula> {
|
|
62
43
|
if (question.query === undefined || question.query === null) {
|
|
63
44
|
throw new Error('A valid query must be provided!')
|
|
@@ -84,18 +65,10 @@ export class SHIPLookupService implements LookupService {
|
|
|
84
65
|
return await this.storage.findRecord({ domain, topics, identityKey })
|
|
85
66
|
}
|
|
86
67
|
|
|
87
|
-
/**
|
|
88
|
-
* Returns documentation specific to this overlay lookup service.
|
|
89
|
-
* @returns A promise that resolves to the documentation string.
|
|
90
|
-
*/
|
|
91
68
|
async getDocumentation(): Promise<string> {
|
|
92
69
|
return SHIPLookupDocs
|
|
93
70
|
}
|
|
94
71
|
|
|
95
|
-
/**
|
|
96
|
-
* Returns metadata associated with this lookup service.
|
|
97
|
-
* @returns A promise that resolves to an object containing metadata.
|
|
98
|
-
*/
|
|
99
72
|
async getMetaData(): Promise<{
|
|
100
73
|
name: string
|
|
101
74
|
shortDescription: string
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { LookupService, LookupQuestion, LookupAnswer, LookupFormula } from '@bsv/overlay'
|
|
1
|
+
import { LookupService, LookupQuestion, LookupAnswer, LookupFormula, AdmissionMode, OutputAdmittedByTopic, OutputSpent, SpendNotificationMode } from '@bsv/overlay'
|
|
2
|
+
import { PushDrop, Utils } from '@bsv/sdk'
|
|
2
3
|
import { SLAPStorage } from './SLAPStorage.js'
|
|
3
|
-
import { Script, PushDrop, Utils } from '@bsv/sdk'
|
|
4
4
|
import { SLAPQuery } from 'src/types.js'
|
|
5
5
|
import SLAPLookupDocs from './SLAPLookup.docs.js'
|
|
6
6
|
|
|
@@ -12,18 +12,15 @@ import SLAPLookupDocs from './SLAPLookup.docs.js'
|
|
|
12
12
|
* records for lookup purposes.
|
|
13
13
|
*/
|
|
14
14
|
export class SLAPLookupService implements LookupService {
|
|
15
|
+
admissionMode: AdmissionMode = 'locking-script'
|
|
16
|
+
spendNotificationMode: SpendNotificationMode = 'none'
|
|
15
17
|
constructor(public storage: SLAPStorage) { }
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
* @param outputIndex - The index of the output in the transaction.
|
|
21
|
-
* @param outputScript - The script of the output to be processed.
|
|
22
|
-
* @param topic - The topic associated with the output.
|
|
23
|
-
*/
|
|
24
|
-
async outputAdded?(txid: string, outputIndex: number, outputScript: Script, topic: string): Promise<void> {
|
|
19
|
+
async outputAdmittedByTopic(payload: OutputAdmittedByTopic): Promise<void> {
|
|
20
|
+
if (payload.mode !== 'locking-script') throw new Error('Invalid mode')
|
|
21
|
+
const { txid, outputIndex, lockingScript, topic } = payload
|
|
25
22
|
if (topic !== 'tm_slap') return
|
|
26
|
-
const result = PushDrop.decode(
|
|
23
|
+
const result = PushDrop.decode(lockingScript)
|
|
27
24
|
const protocol = Utils.toUTF8(result.fields[0])
|
|
28
25
|
const identityKey = Utils.toHex(result.fields[1])
|
|
29
26
|
const domain = Utils.toUTF8(result.fields[2])
|
|
@@ -32,33 +29,17 @@ export class SLAPLookupService implements LookupService {
|
|
|
32
29
|
await this.storage.storeSLAPRecord(txid, outputIndex, identityKey, domain, service)
|
|
33
30
|
}
|
|
34
31
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
* @param outputIndex - The index of the spent output.
|
|
39
|
-
* @param topic - The topic associated with the spent output.
|
|
40
|
-
*/
|
|
41
|
-
async outputSpent?(txid: string, outputIndex: number, topic: string): Promise<void> {
|
|
32
|
+
async outputSpent(payload: OutputSpent): Promise<void> {
|
|
33
|
+
if (payload.mode !== 'none') throw new Error('Invalid payload')
|
|
34
|
+
const { topic, txid, outputIndex } = payload
|
|
42
35
|
if (topic !== 'tm_slap') return
|
|
43
36
|
await this.storage.deleteSLAPRecord(txid, outputIndex)
|
|
44
37
|
}
|
|
45
38
|
|
|
46
|
-
|
|
47
|
-
* Handles the deletion of an output in the topic.
|
|
48
|
-
* @param txid - The transaction ID of the deleted output.
|
|
49
|
-
* @param outputIndex - The index of the deleted output.
|
|
50
|
-
* @param topic - The topic associated with the deleted output.
|
|
51
|
-
*/
|
|
52
|
-
async outputDeleted?(txid: string, outputIndex: number, topic: string): Promise<void> {
|
|
53
|
-
if (topic !== 'tm_slap') return
|
|
39
|
+
async outputEvicted (txid: string, outputIndex: number): Promise<void> {
|
|
54
40
|
await this.storage.deleteSLAPRecord(txid, outputIndex)
|
|
55
41
|
}
|
|
56
42
|
|
|
57
|
-
/**
|
|
58
|
-
* Answers a lookup query.
|
|
59
|
-
* @param question - The lookup question to be answered.
|
|
60
|
-
* @returns A promise that resolves to a lookup answer or formula.
|
|
61
|
-
*/
|
|
62
43
|
async lookup(question: LookupQuestion): Promise<LookupAnswer | LookupFormula> {
|
|
63
44
|
if (question.query === undefined || question.query === null) {
|
|
64
45
|
throw new Error('A valid query must be provided!')
|
|
@@ -96,18 +77,10 @@ export class SLAPLookupService implements LookupService {
|
|
|
96
77
|
return result
|
|
97
78
|
}
|
|
98
79
|
|
|
99
|
-
/**
|
|
100
|
-
* Returns documentation specific to this overlay lookup service.
|
|
101
|
-
* @returns A promise that resolves to the documentation string.
|
|
102
|
-
*/
|
|
103
80
|
async getDocumentation(): Promise<string> {
|
|
104
81
|
return SLAPLookupDocs
|
|
105
82
|
}
|
|
106
83
|
|
|
107
|
-
/**
|
|
108
|
-
* Returns metadata associated with this lookup service.
|
|
109
|
-
* @returns A promise that resolves to an object containing metadata.
|
|
110
|
-
*/
|
|
111
84
|
async getMetaData(): Promise<{
|
|
112
85
|
name: string
|
|
113
86
|
shortDescription: string
|
package/src/WalletAdvertiser.ts
CHANGED
|
@@ -121,13 +121,18 @@ export class WalletAdvertiser implements Advertiser {
|
|
|
121
121
|
resolver = new LookupResolver({ networkPreset: network })
|
|
122
122
|
}
|
|
123
123
|
const advertisements: Advertisement[] = []
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
query
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
124
|
+
let lookupAnswer
|
|
125
|
+
try {
|
|
126
|
+
lookupAnswer = await resolver.query({
|
|
127
|
+
service: protocol === 'SHIP' ? 'ls_ship' : 'ls_slap',
|
|
128
|
+
query: {
|
|
129
|
+
identityKey: this.identityKey
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
} catch (e) {
|
|
133
|
+
console.warn(`Error finding ${protocol} advertisements`, e)
|
|
134
|
+
return advertisements
|
|
135
|
+
}
|
|
131
136
|
// Lookup will currently always return type output-list
|
|
132
137
|
if (lookupAnswer.type === 'output-list') {
|
|
133
138
|
lookupAnswer.outputs.forEach(output => {
|